Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple foreignkeys possibility in Model Relation? #2080

Closed
chojowliu opened this issue Feb 17, 2016 · 30 comments
Closed

Multiple foreignkeys possibility in Model Relation? #2080

chojowliu opened this issue Feb 17, 2016 · 30 comments

Comments

@chojowliu
Copy link

In the loopback model relations section, you can specificity a foreignKey to be referenced in the other model. As far as I know, It will only take one field, but what about I have a composite primary key and want to be referenced in the other model?

Can I do something like?

"foreignKey":["id1","id2"]

@jannyHou jannyHou self-assigned this Feb 17, 2016
@jannyHou
Copy link
Contributor

@chojowliu I think we support composite id, see docs here:
https://docs.strongloop.com/display/public/LB/Model+definition+JSON+file#ModeldefinitionJSONfile-CompositeIDs
But "the composite id is not fully supported for the *byId methods, such as findById. " see details

I am not sure is composite foreign key supported ATM, @raymondfeng could you confirm it? Thanks a lot.

@chojowliu
Copy link
Author

@jannyHou I do know loopback support composite id, but not in the relation section

"relations": { "supplier_acct": { "type": "hasOne", "model": "account", "foreignKey": "supplierId" // you can't have "foreignKey":["id1","id2"], as far as I know we can only use one single column. } }

@chojowliu
Copy link
Author

anyone?

@chojowliu
Copy link
Author

@jannyHou any update on this? I search the web, it seems like people are asking for the same question I have, but none of them been answered.

@jannyHou
Copy link
Contributor

@raymondfeng could you confirm whether we support composite foreignKey? Thanks a lot!

@jmls
Copy link

jmls commented Mar 23, 2016

I would like to know also

@jonathanwoahn
Copy link

+1

@jannyHou
Copy link
Contributor

For anyone interested in multiple foreignKeys, we don't support it as first class now, I label it as a feature, hope we can fully support it in the future.

@peterliapin
Copy link

+1

@archenroot
Copy link

archenroot commented Oct 14, 2016

+1

I welcome even suggestion where to look into the code of loopback and how to try to implement it on my own.

@archenroot
Copy link

I would mark this rather than feature as major issue, as this is preventing usage of loopback in certain scenarios.

I of course understand there is workaround by going with custom method with custom SQL queries where I can write the joins using multiple keys by hand. But it is breaking the beauty of model driven design of loopback and in general I think direct SQL queries method should be used only in edge scenarios as temporary workaround.

@jannyHou jannyHou added the major label Oct 26, 2016
@jannyHou
Copy link
Contributor

@archenroot make sense. Labelled it as major

@jannyHou
Copy link
Contributor

jannyHou commented Nov 18, 2016

Copied from #2955 (comment)
@elfahxh let's keep discussion here.
Support composite keys in embeds Relation:

  • Scenario:

I created two Models, Model-B is an embedded model in Mode-A, Model-A must have sharding key which have two fields. When I call such related method, Model-A.Model-B.create(), will failed.
The root-cause is that, underline, it will call updateAttributes() of Model-A, while the search filter only have "_id" field, cannot define a combined multiple keys to find Model-A from database. hence, will encounter a failure.

@skyserpent
Copy link

+1

1 similar comment
@darknos
Copy link

darknos commented Dec 15, 2016

+1

@jannyHou
Copy link
Contributor

Anyone also interested in this feature please do 👍 on the first comment :) instead of adding new comments. Thanks!

@archenroot
Copy link

Any update on this?

@jannyHou
Copy link
Contributor

This story is already in backlog, we will make an investigation in the future.

@bajtos
Copy link
Member

bajtos commented Apr 7, 2017

Possibly related: #2046

@bajtos
Copy link
Member

bajtos commented Apr 7, 2017

and also #126

@richard-dev-mx
Copy link

+1

@kjdelisle
Copy link
Contributor

Given that [email protected] is coming soon, we're not going to be making new features for core components.

@mikollaay
Copy link

+1

1 similar comment
@bolmsten
Copy link

+1

@shallker
Copy link

still looking for multiple ids / keys support...

@ghost
Copy link

ghost commented Jul 20, 2018

+1

@archenroot
Copy link

@kjdelisle - what was the reason for closing this issue? Fact that [email protected] has this feature built in or fact that you simply don't have time to look at this or that we should ask for this feature within connectors instead of core?

Thanks for answer.

@archenroot
Copy link

@ALL - I opened this issue on Oracle and Postgres connector as well, but it is being overlooked at all....

loopbackio/loopback-connector-oracle#87
loopbackio/loopback-connector-postgresql#184

@acknowsrl
Copy link

News about this feature in loopback 4?
Thanks

@bajtos
Copy link
Member

bajtos commented Oct 9, 2018

Hello, LoopBack 4.0 release is very close, we don't have bandwidth to work on composite foreign keys in LoopBack 3.x. I opened a new issue in loopback-next, I'd like us to consider the problem of composite keys in a wider context. Let's move further discussions to the new issue please.

loopbackio/loopback-next#1830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests