More than one foreign key from the same table #2974
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Let me start with some reasoning why multiple So how to "fix" this: As What could be improved here is the derive itself, so that we already issue an error there indicating this solution. If someone is interested in contributing this improvement I can add details about the potential implementation. |
Beta Was this translation helpful? Give feedback.
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 resolveTransactions::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 onbelongs_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 …