edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

2nd level of nesting in query builder returns unexpected results

Open OriginalEXE opened this issue 3 years ago • 1 comments

  • EdgeDB Version: 0.20.7
  • EdgeDB CLI Version: 1.1.1+932d5c6

Given the following schema:

module default {
  type users {
    required property email -> str {
      constraint exclusive;
    }
    required property name -> str;
    multi link team_memberships := .<user[is team_users];
  }

  type teams {
    required property name -> str;
    required property slug -> str {
      constraint exclusive;
    }
    multi link team_users := .<team[is team_users];
  }

  scalar type TeamRole extending enum<Owner, Editor>;

  type team_users {
    link user -> users {
      on target delete delete source;
    }
    required link team -> teams {
      on target delete delete source;
    }
    required property role -> TeamRole;
  }
}

The following query:

db
    .select(db.teams, (dbTeam) => ({
      id: true,
      name: true,
      slug: true,
      team_users: {
        id: true,
        role: true,
        user: {
          limit: 1,
          id: true,
          name: true,
          email: true,
        },
      },
    }))
    .assert_single()

returns unexpected results. While id and role of team_users return as expected (they are different for each team member), the user object always returns the same (first) user. Also, for some reason I am forced to have that limit: 1, in there even though in schema it is a defined as a single link.

When I inspect the query generated, the fault seems to be with the extraction of scopes, and I see no way of disabling that behavior.

Running the same query with the same amount of nesting directly in edgedb works as expected.

Any help appreciated, thanks!

OriginalEXE avatar Apr 18 '22 23:04 OriginalEXE

This seems to be a bug in edgedb itself, I've opened an issue there: https://github.com/edgedb/edgedb/issues/3794

jaclarke avatar Apr 25 '22 16:04 jaclarke