Skip to content

More than one foreign key from the same table #2974

Answered by weiznich
aymanalqadhi asked this question in Q&A
Discussion options

You must be logged in to vote

Let me start with some reasoning why multiple belongs_to attribute referencing the same table are not allowed. The issue there is that we cannot say which of the referenced dependencies should be used to resolve Transactions::belonging_to(&user). We could likely require that you always need to specify the used foreign key column, but that would add unneeded boiler plate code for the case where only on belongs_to attribute is given.

So how to "fix" this: As Transactions::belonging_to(&user) only constructs a simple query (users::table.filter(users::id.eq_any(foreign_keys))) you can just write this query explicitly.

What could be improved here is the derive itself, so that we already issue …

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@aymanalqadhi
Comment options

@weiznich
Comment options

@aymanalqadhi
Comment options

@Mingun

This comment was marked as off-topic.

@weiznich

This comment was marked as off-topic.

Answer selected by aymanalqadhi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants