sea-orm-sync/src/entity/DESIGN.md
Consider the following method:
fn left_join<E>(self) -> Self
where
E: EntityTrait,
{
// ...
}
which has to be invoked like:
.left_join::<fruit::Entity>()
If we instead do:
fn left_join<E>(self, _: E) -> Self
where
E: EntityTrait,
{
// ...
}
then the Turbofish can be omitted:
.left_join(fruit::Entity)
provided that fruit::Entity is a unit struct.
Instead of:
fn has_many(entity: Entity, from: Column, to: Column);
has_many(cake::Entity, cake::Column::Id, fruit::Column::CakeId)
we'd prefer having a builder and stating the params explicitly:
has_many(cake::Entity).from(cake::Column::Id).to(fruit::Column::CakeId)
Consider the following two methods, which accept the same parameter but in different forms:
fn method_with_model(m: Model) { ... }
fn method_with_active_model(a: ActiveModel) { ... }
We would define a trait
pub trait IntoActiveModel {
fn into_active_model(self) -> ActiveModel;
}
Such that Model and ActiveModel both impl this trait.
In this way, we can overload the two methods:
pub fn method<A>(a: A)
where
A: IntoActiveModel,
{
let a: ActiveModel = a.into_active_model();
...
}