Query engine generates wrong SQL queries for Hierarchical Data #399
Comments
I can reproduce this bug. GraphQL trees that photon send to the engine so that we can easily debug in engine: query {
findOneCategory(where: { id: "ck5bbt33h000001mj6s6c7c0k" }) {
id
name
parent {
id
}
}
}
query {
findManyCategory {
id
name
parent {
id
}
}
}
|
I just tried to adjust schema a little bit and regenerate photon client. I renamed model Category {
id String @default(cuid()) @id
name String
parent Category? @relation(name: "Subcategories", references: id)
smth Category[] @relation(name: "Subcategories", onDelete: CASCADE, references: parent)
} After that I tried to run following query: photon
.categories
.findOne({
where: { id: 'cjs86oooa007w0c94qym4xqqf' },
select: { id: true, name: true, parent: { select: { id: true }, smth: { select: { id: true } } }
}); And all works fine. It looks like the root of problem is that relation name and field name are same. I hope this can help you. |
Just tried to adjust schema in following way: model Category {
id String @default(cuid()) @id
name String
parent Category? @relation(name: "ParentChildRelation", references: id)
subcategories Category[] @relation(name: "ParentChildRelation", onDelete: CASCADE, references: parent)
} In this case "relation name" ( After that I tried to adjust schema in following way: model Category {
id String @default(cuid()) @id
name String
parent Category? @relation(name: "Subcategories", references: id)
children Category[] @relation(name: "Subcategories", onDelete: CASCADE, references: parent)
} And all works fine. Looks like the problem appears only in one case: when field name === |
Internal Note: I suspect that the root cause might be use of |
@mavilein already tried without |
Ping @braska |
I tried it with latest available version. Looks like issue resolved. Thanks! |
Awesome, thanks for the update @braska! |
Here is datamodel:
Here is example of the query:
This query generates following SQL queries to DB (
new Photon({ debug: true, log: true });
):So Query Engine tries to query all categories where
parent='cjs86oooa007w0c94qym4xqqf'
, which is completely unexpected behavior.With following query:
... engine returns
error: PhotonQueryError: Reason: Expected at most 1 item for 'parent', got 13
The text was updated successfully, but these errors were encountered: