mirror of
https://github.com/strapi/strapi.git
synced 2025-10-18 19:43:22 +00:00
[Bugfix] take the correct localField when having a manyToOne RS
This commit is contained in:
parent
382f52a2e8
commit
83da9fa38a
@ -40,17 +40,13 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
if (filters.sort) {
|
||||
qb.orderBy(filters.sort.key, filters.sort.order);
|
||||
}
|
||||
|
||||
Object.keys(filters.relations).forEach(
|
||||
(relationName) => {
|
||||
const ast = <%= globalID.toLowerCase() %>.associations.find(a => a.alias === relationName);
|
||||
if (ast) {
|
||||
const model = ast.plugin ?
|
||||
strapi.plugins[ast.plugin].models[ast.model ? ast.model : ast.collection] :
|
||||
strapi.models[ast.model ? ast.model : ast.collection];
|
||||
strapi.plugins[ast.plugin].models[ast.model || ast.collection] :
|
||||
strapi.models[ast.model || ast.collection];
|
||||
|
||||
qb.distinct();
|
||||
|
||||
@ -70,8 +66,11 @@ module.exports = {
|
||||
const externalKey = ast.type === 'collection' ?
|
||||
`${model.collectionName}.${ast.via}` :
|
||||
`${model.collectionName}.${model.primaryKey}`;
|
||||
const internalKey = !ast.dominant ? `${<%= globalID.toLowerCase() %>.collectionName}.${<%= globalID.toLowerCase() %>.primaryKey}` :
|
||||
ast.via === <%= globalID.toLowerCase() %>.collectionName ? `${<%= globalID.toLowerCase() %>.collectionName}.${ast.alias}` : `${<%= globalID.toLowerCase() %>.collectionName}.${<%= globalID.toLowerCase() %>.primaryKey}`;
|
||||
const internalKey = !ast.dominant
|
||||
? `${<%= globalID.toLowerCase() %>.collectionName}.${<%= globalID.toLowerCase() %>.primaryKey}`
|
||||
: ast.via === <%= globalID.toLowerCase() %>.collectionName
|
||||
? `${<%= globalID.toLowerCase() %>.collectionName}.${ast.alias}`
|
||||
: `${<%= globalID.toLowerCase() %>.collectionName}.${<%= globalID.toLowerCase() %>.primaryKey}`;
|
||||
|
||||
qb.innerJoin(relationTable, externalKey, internalKey);
|
||||
}
|
||||
@ -88,6 +87,10 @@ module.exports = {
|
||||
|
||||
qb.offset(filters.start);
|
||||
qb.limit(filters.limit);
|
||||
|
||||
if (filters.sort) {
|
||||
qb.orderBy(filters.sort.key, filters.sort.order);
|
||||
}
|
||||
}).fetchAll({
|
||||
withRelated: populate
|
||||
});
|
||||
|
@ -26,9 +26,14 @@ module.exports = {
|
||||
const populate = <%= globalID %>.associations
|
||||
.filter(ast => ast.autoPopulate)
|
||||
.reduce((acc, ast) => {
|
||||
const from = ast.plugin ? `${ast.plugin}_${ast.model}` : ast.collection ? ast.collection : ast.model;
|
||||
// Strapi Model
|
||||
const model = ast.plugin
|
||||
? strapi.plugins[ast.plugin].models[ast.collection || ast.model]
|
||||
: strapi.models[ast.collection || ast.model];
|
||||
|
||||
const from = model.collectionName;
|
||||
const as = ast.alias;
|
||||
const localField = !ast.dominant ? '_id' : ast.via === <%= globalID %>.collectionName || ast.via === 'related' ? '_id' : ast.alias;
|
||||
const localField = ast.dominant ? '_id' : ast.via === <%= globalID %>.collectionName || ast.via === 'related' ? '_id' : ast.alias;
|
||||
const foreignField = ast.filter ? `${ast.via}.ref` :
|
||||
ast.dominant ?
|
||||
(ast.via === <%= globalID %>.collectionName ? ast.via : '_id') :
|
||||
|
Loading…
x
Reference in New Issue
Block a user