Closed frederikhors closed 1 year ago
Hey @frederikhors, thanks for the reporting!! I want to understand the situation before formulating the solution.
I guess the schema is similar to above?
There are two paths between cake
and baker
cake
<-> baker
cake
<-> cake_bakers
<-> baker
Yeah. I think the issue is because we have tenant_id
column on both tables. And sea-orm-cli goes crazy about it! :smile:
I think I'm seeing something similar on 0.10.*.
I was previously using 0.9.0 without issue.
error[E0119]: conflicting implementations of trait `std::fmt::Display` for type `sea_orm_active_enums::Type`
--> entity/src/sea_orm_active_enums.rs:7:53
|
7 | Debug, Display, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Deserialize, Serialize,
| ------- first implementation here ^^^^^^^^^^^^^^^^ conflicting implementation for `sea_orm_active_enums::Type`
|
= note: this error originates in the derive macro `DeriveActiveEnum` (in Nightly builds, run with -Z macro-backtrace for more info)
Imports and macro for the file in question:
use sea_orm::{entity::prelude::*, strum::Display};
use serde::{Deserialize, Serialize};
#[derive(
Debug, Display, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Deserialize, Serialize,
)]
Downgrading to 0.9.3 solves the issue. Let me know if you'd like me to open a separate issue @billy1624.
I think this is not the same.
I was talking about this in the discord a bit.
The generator seems to generate all relations as Related
functions without considering multiple relationships between two entities.
You can manually code the solution to this with, I believe, Chained Relations, so in the example could do:
// cake.rs
// ....
pub struct CakeBakersLink;
impl Linked for CakeBakersLink {
type FromEntity = Entity;
type ToEntity = cake_bakers::Entity;
fn link(&self) -> Vec<RelationDef> {
vec![
cake_bakers::Relation::Cakes.def().rev(),
cake_bakers::Relation::Bakers.def(),
]
}
}
So the default relationship from Cake will give you its recipe author. To get its bakers, you use CakeBakersLink
. You can also ditch the Relation
function entirely and also make the recipe author relationship a chained one, too, so that it's more clear.
Short term maybe the generator should generate Linked
structs for secondary relationships for entities.
And long term, maybe make it customizable for how the user wants to handle relationships. For example, I think I'd like the ability to generate all relationships as Linked
instead of Related
, except for linking tables like cake_bakers
. I like chained relationships because the Linked
struct can be named to give context. Cake::find().also_find_related(Baker)
is less intuitive to me than Cake::find().also_find_linked(RecipeAuthorBakerLink)
(which can be generated based on column name).
Hey @TurtIeSocks, the problem you mention isn't related to this issue.
In sea-orm 0.10.x, DeriveActiveEnum
implement Display
trait for you. So, you don't need to derive or implement it on your own.
Hey everyone, thanks for the input! I've created https://github.com/SeaQL/sea-orm/pull/1298 which will skip the implementation of
impl Related<super::baker::Entity> for Entity {
fn to() -> RelationDef {
Relation::Baker.def()
}
}
While keeping this
impl Related<super::baker::Entity> for Entity {
fn to() -> RelationDef {
super::cakes_bakers::Relation::Baker.def()
}
fn via() -> Option<RelationDef> {
Some(super::cakes_bakers::Relation::Cake.def().rev())
}
}
Hey everyone, thanks for the input! I've created #1298 which will skip the implementation of
impl Related<super::baker::Entity> for Entity { fn to() -> RelationDef { Relation::Baker.def() } }
While keeping this
impl Related<super::baker::Entity> for Entity { fn to() -> RelationDef { super::cakes_bakers::Relation::Baker.def() } fn via() -> Option<RelationDef> { Some(super::cakes_bakers::Relation::Cake.def().rev()) } }
Can you release this ASAP?
I'll publish it tomorrow morning
sea-orm-cli 0.10.6 has been published https://crates.io/crates/sea-orm-cli/0.10.6
Description
Using unfortunately on a new PC the new
sea-orm-cli@0.10.5
instead of0.10.2
I get the below error with the same PG schema.I cannot publish code because of NDA.
Actual Behavior
It gives this error after generation:
Versions