Check for alias as well when deciding whether filter requires relationship addition.
This commit is contained in:
parent
b217e83b31
commit
3e51dde6d2
|
@ -346,21 +346,25 @@ class InternalBuilder {
|
||||||
const { relationships, endpoint, tableAliases: aliases } = this.query
|
const { relationships, endpoint, tableAliases: aliases } = this.query
|
||||||
const tableName = endpoint.entityId
|
const tableName = endpoint.entityId
|
||||||
const fromAlias = aliases?.[tableName] || tableName
|
const fromAlias = aliases?.[tableName] || tableName
|
||||||
|
const matches = (possibleTable: string) =>
|
||||||
|
filterKey.startsWith(`${possibleTable}`)
|
||||||
if (!relationships) {
|
if (!relationships) {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
for (const relationship of relationships) {
|
for (const relationship of relationships) {
|
||||||
|
const relatedTableName = relationship.tableName
|
||||||
|
const toAlias = aliases?.[relatedTableName] || relatedTableName
|
||||||
// this is the relationship which is being filtered
|
// this is the relationship which is being filtered
|
||||||
if (
|
if (
|
||||||
filterKey.startsWith(`${relationship.tableName}.`) &&
|
(matches(relatedTableName) || matches(toAlias)) &&
|
||||||
relationship.to &&
|
relationship.to &&
|
||||||
relationship.tableName
|
relationship.tableName
|
||||||
) {
|
) {
|
||||||
const relatedTableName = relationship.tableName
|
|
||||||
const toAlias = aliases?.[relatedTableName] || relatedTableName
|
|
||||||
let subQuery = mainKnex
|
let subQuery = mainKnex
|
||||||
.select(mainKnex.raw(1))
|
.select(mainKnex.raw(1))
|
||||||
.from({ [toAlias]: relatedTableName })
|
.from({ [toAlias]: relatedTableName })
|
||||||
|
// relationships should never have more than the base limit
|
||||||
|
.limit(getBaseLimit())
|
||||||
let mainTableRelatesTo = toAlias
|
let mainTableRelatesTo = toAlias
|
||||||
if (relationship.through) {
|
if (relationship.through) {
|
||||||
const throughAlias =
|
const throughAlias =
|
||||||
|
|
Loading…
Reference in New Issue