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

EntityObjectRelationBuilder's get_relation doesn't account for on_condition #132

Open
joshuaclayton opened this issue Apr 19, 2023 · 1 comment
Assignees

Comments

@joshuaclayton
Copy link

Description

With an on_condition within an entity relationship, the corresponding SQL query doesn't incorporate that scope.

Imagine a simple structure where a BlogPost has a published boolean and an FK to Author. By defining two relationships:

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        has_many = "super::posts::Entity"
    )]
    Posts,
    #[sea_orm(
        has_many = "super::posts::Entity",
        on_condition = r#"crate::entities::posts::Column::Published.eq(true)"#
    )]
    PublishedPosts,
}

I would expect accessing publishedPosts to apply the on_condition:

    builder.register_entity::<crate::entities::authors::Entity>(vec![
        entity_object_relation_builder
            .get_relation::<crate::entities::authors::Entity, crate::entities::posts::Entity>(
                "posts",
                crate::entities::authors::Relation::Posts.def(),
            ),
        entity_object_relation_builder
            .get_relation::<crate::entities::authors::Entity, crate::entities::posts::Entity>(
                "publishedPosts",
                dbg!(crate::entities::authors::Relation::PublishedPosts.def()),
            ),
    ]);

However, the on_condition is not applied.

Expected Behavior

I expect the additional scoping from the on_condition to apply when the GraphQL query is run.

Actual Behavior

The foreign key is honored but not the additional on_condition.

Reproduces How Often

Yes.

Versions

Latest Seaography.

Additional Information

I think I've narrowed down the location where the on_condition should be applied:

let condition = Condition::all().add(to_col.eq(parent.get(from_col)));

@karatakis
Copy link
Collaborator

Thanks @joshuaclayton for taking the time to report the issue. I can confirm that seaography does not take in mind the on_condition property. We will take care of the issue when we will update to sea-orm version 0.12

@karatakis karatakis self-assigned this Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants