Expand SeaORM entity generator with Seaography related data#1599
Expand SeaORM entity generator with Seaography related data#1599billy1624 merged 31 commits intoSeaQL:masterfrom
Conversation
| impl Related<super::fruit::Entity> for Entity { | ||
| fn to() -> RelationDef { | ||
| Relation::Fruit.def() | ||
| } | ||
| } | ||
|
|
||
| impl Related<super::filling::Entity> for Entity { | ||
| fn to() -> RelationDef { | ||
| super::cake_filling::Relation::Filling.def() | ||
| } | ||
| fn via() -> Option<RelationDef> { | ||
| Some(super::cake_filling::Relation::Cake.def().rev()) | ||
| } | ||
| #[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] | ||
| pub enum RelatedEntity { | ||
| #[sea_orm(entity = "super::fruit::Entity", to = "Relation::Fruit.def()")] | ||
| Fruit, | ||
| #[sea_orm (entity = "super::filling::Entity", to = "super::cake_filling::Relation::Filling.def()", via = "Some(super::cake_filling::Relation::Cake.def().rev())")] | ||
| Filling |
There was a problem hiding this comment.
I think we should keep generating the plain old Related<T>. With that in mind, if user pass in a --seaography flag to the sea-orm-cli generate entity, then, an additional RelatedEntity enum will be generated.
I imagine the derive attribute of each variant in the RelatedEntity could be... to take advantage of the existing Related<T> impl and avoid saying the same thing twice.
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)]
pub enum RelatedEntity {
#[sea_orm (entity = "super::filling::Entity")]
Filling
}| impl seaography::RelationBuilder for Relation { | ||
| fn get_relation(&self, context: & 'static seaography::BuilderContext) -> async_graphql::dynamic::Field { | ||
| let builder = seaography::EntityObjectRelationBuilder { context }; | ||
| match self { | ||
| Self::Fruit => builder.get_relation:: <Entity, super::fruit::Entity>("fruit", Self::Fruit.def()), | ||
| _ => panic!("No relations for this entity") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl seaography::RelationBuilder for RelatedEntity { | ||
| fn get_relation(&self, context: & 'static seaography::BuilderContext) -> async_graphql::dynamic::Field { | ||
| let builder = seaography::EntityObjectViaRelationBuilder { context }; | ||
| match self { | ||
| Self::Fruit => builder.get_relation:: <Entity, super::fruit::Entity>("fruit"), | ||
| Self::Filling => builder.get_relation:: <Entity, super::filling::Entity>("filling"), | ||
| _ => panic!("No relations for this entity") | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
These async-graphql constructors for relations can be moved into sea-orm-macros in which those methods will be generated when the seaography feature is enabled
billy1624
left a comment
There was a problem hiding this comment.
Hey @karatakis, thanks for the huge PR! Great work! I just leave a few comments :)
* Bring old Related Impl trait generation * Modify DeriveRelatedEntity to gen impl seaography::RelationBuilder * Generate RelatedEntity enum when seaography flag is enabled
|
Hey @karatakis, thanks for the changes!! Please feel free to ping me once it's finished or you need help :P |
|
I am done. @billy1624 could you please take a look if the last changes resolve the issues you pointed out ? |
* relations with suffix are definition based * Rev => Reverse easier to read * snake_case to cameCase for name generation
|
I used the proposed changes in the following SeaQL/seaography#131 |
|
Great work. This is really significant. We will try to roll out SeaORM 0.12 sooner and I think this is really a 'killer app' |
billy1624
left a comment
There was a problem hiding this comment.
Hey @karatakis, look good!! Neat and clean!
Can we update the Cargo.toml in SeaQL/seaography#131 and make it depends on this PR. I want to compile, see it in action and play with it :)
There was a problem hiding this comment.
I think we can arrange a merge @billy1624 if there is no other outstanding PR to sea-orm-cli
We want to be extra careful not to breaking any existing features though.
billy1624
left a comment
There was a problem hiding this comment.
Hey @karatakis, I just added two commits
-
Derive
impl seaography::RelationBuilder for RelatedEntitywhenseaographyfeature is enabled 0833478 -
A demo for how to construct the
async-graphqlquery root for entity with/withoutRelatedEntityc84294e
Please check :)
|
The seaography feature in the root Cargo.toml needs a '?' for macros |
Co-authored-by: Chris Tsang <[email protected]>
|
Indeed! Thanks @tyt2y3 for catching that |
This reverts commit 6b16698.
|
Emmmm... no. We're wrong. |
* Optional Field SeaQL/sea-orm#1513 * .gitignore SeaQL/sea-orm#1334 * migration table custom name SeaQL/sea-orm#1511 * OR condition relation SeaQL/sea-orm#1433 * DerivePartialModel SeaQL/sea-orm#1597 * space for migration file naming SeaQL/sea-orm#1570 * composite key up to 12 SeaQL/sea-orm#1508 * seaography integration SeaQL/sea-orm#1599 * QuerySelect SimpleExpr SeaQL/sea-orm#1702 * sqlErr SeaQL/sea-orm#1707 * migration check SeaQL/sea-orm#1519 * postgres array SeaQL/sea-orm#1565 * param intoString SeaQL/sea-orm#1439 * **skipped** re-export SeaQL/sea-orm#1661 * ping SeaQL/sea-orm#1627 * on empty do nothing SeaQL/sea-orm#1708 * on conflict do nothing SeaQL/sea-orm#1712 * **skipped** upgrade versions * active enum fail safe SeaQL/sea-orm#1374 * relation generation check SeaQL/sea-orm#1435 * entity generation bug SeaQL/sea-schema#105 * **skipped** bug fix that does not require edits * EnumIter change SeaQL/sea-orm#1535 * completed and fixed a previous todo SeaQL/sea-orm#1570 * amended wordings and structures * Edit * Remove temp file --------- Co-authored-by: Billy Chan <[email protected]>
🎉 Released In 0.12.1 🎉Thank you everyone for the contribution! |
PR Info
query_root.rsseaography#130New Features
seaographyflag tosea-orm-cliseaographyrelated information tosea-orm-codegenDeriveEntityRelatedmacroDeriveEntityRelatedtosea-orm-codegen