mirror of
https://github.com/strapi/strapi.git
synced 2025-11-11 07:39:16 +00:00
Support one-to-one relationship with DataLoader
This commit is contained in:
parent
639c635885
commit
4e23e872ed
@ -47,7 +47,7 @@ module.exports = {
|
|||||||
|
|
||||||
if (query.single) {
|
if (query.single) {
|
||||||
// Return object instead of array for one-to-many relationship.
|
// Return object instead of array for one-to-many relationship.
|
||||||
return data.find(entry => (entry._id || entry.id || '').toString() === query.params[ref.primaryKey].toString());
|
return data.find(entry => entry[ref.primaryKey].toString() === (query.params[ref.primaryKey] || '').toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extracting ids from original request to map with query results.
|
// Extracting ids from original request to map with query results.
|
||||||
@ -83,7 +83,7 @@ module.exports = {
|
|||||||
query: {}
|
query: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
params.query[query.alias] = _.uniq(query.ids.map(x => x.toString())) ;
|
params.query[query.alias] = _.uniq(query.ids.filter(x => !_.isEmpty(x)).map(x => x.toString())) ;
|
||||||
|
|
||||||
// Run query and remove duplicated ID.
|
// Run query and remove duplicated ID.
|
||||||
const request = await strapi.plugins['content-manager'].services['contentmanager'].fetchAll({ model }, params);
|
const request = await strapi.plugins['content-manager'].services['contentmanager'].fetchAll({ model }, params);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user