Open oersted opened 2 years ago
Are multi-column Relations even supported by SeaORM in general? The definition of the RelationDef struct only accepts a single from_col
and to_col
.
What more idiomatic alternative would you suggest? Should I add a separate unique id to each table and use that for the relations?
If it is not supported, why does the generation not fail? And why does it fall back on this Block1
& Block2
pattern?
Hey @oersted, thanks for the report! SeaORM did support multi-column foreign keys:
But codegen don't support that yet. What's the database you're using?
Thank you for the follow-up. I'm using Sqlite.
I have a similar problem and am able to manually fix it by replacing
from = "Column::SampleId",
to = "super::samples::Column::ProjectId",
With
from = "(Column::SampleId, Column::ProjectId)",
to = "(super::samples::Column::Id, super::samples::Column::ProjectId)",
But it's a bit painful to have to constantly fix it when regenerating the code. @billy1624 can you point me in the direction of where this should be fixed? I want to give it a try.
Description
For single-column foreign keys, the generated parent and child have a relation to each other. The parent has a simple
has_many
and the child has abelong_to
with the details of the foreign key columns and on update/delete policies.For multi-column foreign keys though, it generates one
belongs_to
relation on the child per column and doesn't generate ahas_many
relation on the parent. Therefore, for example, usingfind_with_related
doesn't compile.Steps to Reproduce
It will generate both of these files.
Expected Behavior
It should generate a
has_many
relation onBlock
pointing toRule
. Simply adding this by hand doesn't trivially work, I'm unsure how theRelated
trait should be implemented for a double relation likeBlock1
andBlock2
, is the relation on the child even correct?Even if the support for this in the generation is not implemented in the short term, I would really appreciate some guidance on how to define the Entity manually so that this works as intended.
Versions
sea-orm 0.8.0