Complex where with HAS condition #2720
-
|
Hello! I have a question regarding relation conditions in a HAS object for complex wheres. Given the following query: {
drivers(
where: {
OR: [
{HAS: {relation: "employee", condition: {column: NAME, value: "Peter"}}},
{column: ID, operator: EQ, value: "6217"}
]
}
) {
data {
id
name
employee {
name
}
}
}
}The intend here is to find all drivers that have a related employee with name However, the By coincidence, both database tables have a Am I misusing the For good measure, here's my schema definition for the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @DrPowerSlam, You've identified a legitimate design limitation in the current implementation. You're correct that the Why this happens: In condition: {$name} // Uses the parent WHERE input typeThis means for your query, the HAS condition's Current workaround: Don't specify drivers(where: _ @whereConditions): [Driver!]! @allThen you can use: where: {
HAS: {
relation: "employees"
condition: { column: "name", value: "Peter" } # String literal
}
}Ideal solution: The directive would need to be enhanced to dynamically resolve the column enum based on the relation name, but this would require significant schema generation changes since the relation name is only known at query time, not schema build time. This might be worth filing as a feature request if the workaround doesn't meet your needs! |
Beta Was this translation helpful? Give feedback.
Hi @DrPowerSlam,
You've identified a legitimate design limitation in the current implementation. You're correct that the
columnfield inside HAS conditions uses the parent model's column enum rather than the related model's enum.Why this happens:
In
WhereConditionsServiceProvider::createHasConditionsInputType(), theconditionfield recursively references the same parent input type:condition: {$name} // Uses the parent WHERE input typeThis means for your query, the HAS condition's
columnfield is typed asDriverColumn, even though you're actually filtering theemployeesrelation.Current workaround:
Don't specify
columnsEnum(orcolumns) on the directive. This makes thecolumnfield ac…