Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support has_one relation #90

Closed
billy1624 opened this issue Nov 3, 2022 · 1 comment · Fixed by #114
Closed

Support has_one relation #90

billy1624 opened this issue Nov 3, 2022 · 1 comment · Fixed by #114

Comments

@billy1624
Copy link
Member

Motivation

Currently, we only support has_many and belongs_to but not has_one. We should support it as well.

Compiling the entity with has_one relation will fail.

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, seaography::macros::RelationsCompact)]
pub enum Relation {
    #[sea_orm(has_one = "super::film_category::Entity")]
    FilmCategory,
}
error: macros that expand to items must be delimited with braces or followed by a semicolon
  --> src/entities/category.rs:21:56
   |
21 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, seaography::macros::RelationsCompact)]
   |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the derive macro `seaography::macros::RelationsCompact` (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc-macro derive produced unparseable tokens
  --> src/entities/category.rs:21:56
   |
21 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, seaography::macros::RelationsCompact)]
   |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Syn(Error("`#[sea_orm]` got unknown `has_one` argument. Supported arguments are `belongs_to`, `from`, `has_many`, `on_delete`, `on_update`, `to`"))
  --> src/entities/category.rs:21:56
   |
21 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, seaography::macros::RelationsCompact)]
   |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the derive macro `seaography::macros::RelationsCompact` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `category::Model: ComplexObject` is not satisfied
 --> src/entities/category.rs:8:5
  |
8 |     async_graphql::SimpleObject,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ComplexObject` is not implemented for `category::Model`
  |
  = help: the following other types implement trait `ComplexObject`:
            actor::Model
            address::Model
            city::Model
            country::Model
            customer::Model
            film::Model
            film_actor::Model
            film_category::Model
          and 7 others
  = note: this error originates in the derive macro `async_graphql::SimpleObject` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `seaography-sqlite-example` due to 4 previous errors

Proposed Solutions

Updating seaography::macros::RelationsCompact to parse and implement dataloader for has_one relation.

@karatakis
Copy link
Collaborator

It is supported in #114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants