rimecms 0.23.23 → 0.23.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -105,6 +105,34 @@ export const buildWhereParam = ({ query, slug, db, locale, tables, configCtx })
|
|
|
105
105
|
const [to, localized] = [fieldConfig.relationTo, fieldConfig.localized];
|
|
106
106
|
const relationTableName = `${slug}Rels`;
|
|
107
107
|
const relationTable = getTable(relationTableName);
|
|
108
|
+
// Handle multi-valued relations specially when operator is `equals` to provide
|
|
109
|
+
// strict equality semantics (the relation set must equal the provided value(s)).
|
|
110
|
+
if (fieldConfig.many && operator === 'equals') {
|
|
111
|
+
// Accept array inputs, repeated params, or CSV values for equality checks
|
|
112
|
+
let values = Array.isArray(rawValue)
|
|
113
|
+
? rawValue
|
|
114
|
+
: typeof rawValue === 'string' && rawValue.includes(',')
|
|
115
|
+
? rawValue.split(',')
|
|
116
|
+
: [value];
|
|
117
|
+
// Ensure values are unique
|
|
118
|
+
values = Array.from(new Set(values));
|
|
119
|
+
// Owners with total relation count equal to values.length
|
|
120
|
+
const ownersWithTotalCount = db
|
|
121
|
+
.select({ id: relationTable.ownerId })
|
|
122
|
+
.from(relationTable)
|
|
123
|
+
.where(and(...(localized ? [eq(relationTable.locale, locale)] : [])))
|
|
124
|
+
.groupBy(relationTable.ownerId)
|
|
125
|
+
.having(drizzleORM.eq(drizzleORM.count(relationTable.id), values.length));
|
|
126
|
+
// Owners with matching relations count equal to values.length
|
|
127
|
+
const ownersWithMatchingCount = db
|
|
128
|
+
.select({ id: relationTable.ownerId })
|
|
129
|
+
.from(relationTable)
|
|
130
|
+
.where(and(drizzleORM.inArray(relationTable[`${to}Id`], values), ...(localized ? [eq(relationTable.locale, locale)] : [])))
|
|
131
|
+
.groupBy(relationTable.ownerId)
|
|
132
|
+
.having(drizzleORM.eq(drizzleORM.count(relationTable.id), values.length));
|
|
133
|
+
return and(inArray(table.id, ownersWithTotalCount), inArray(table.id, ownersWithMatchingCount));
|
|
134
|
+
}
|
|
135
|
+
// Default behavior (membership checks with in_array etc.)
|
|
108
136
|
const conditions = [fn(relationTable[`${to}Id`], value)];
|
|
109
137
|
if (localized) {
|
|
110
138
|
conditions.push(eq(relationTable.locale, locale));
|