mirror of
https://github.com/strapi/strapi.git
synced 2025-07-26 18:38:46 +00:00
Merge branch 'master' into fix-cm-entry-relations
This commit is contained in:
commit
e6a14367f3
@ -236,6 +236,7 @@ module.exports = function(strapi) {
|
|||||||
const association = definition.associations
|
const association = definition.associations
|
||||||
.filter(association => association.nature.toLowerCase().indexOf('morph') !== -1)
|
.filter(association => association.nature.toLowerCase().indexOf('morph') !== -1)
|
||||||
.filter(association => association.alias === path || association.via === path)[0];
|
.filter(association => association.alias === path || association.via === path)[0];
|
||||||
|
|
||||||
if (association) {
|
if (association) {
|
||||||
// Override on polymorphic path only.
|
// Override on polymorphic path only.
|
||||||
if (_.isString(path) && path === association.via) {
|
if (_.isString(path) && path === association.via) {
|
||||||
@ -252,7 +253,11 @@ module.exports = function(strapi) {
|
|||||||
strapi.plugins[association.plugin].models[association.collection || association.model]:
|
strapi.plugins[association.plugin].models[association.collection || association.model]:
|
||||||
strapi.models[association.collection || association.model];
|
strapi.models[association.collection || association.model];
|
||||||
|
|
||||||
return `${association.alias}.${model.collectionName}`;
|
return {
|
||||||
|
[`${association.alias}.${model.collectionName}`]: function(query) {
|
||||||
|
query.orderBy('created_at', 'desc');
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +218,28 @@ module.exports = {
|
|||||||
strapi.plugins[obj.source].models[obj.ref]:
|
strapi.plugins[obj.source].models[obj.ref]:
|
||||||
strapi.models[obj.ref];
|
strapi.models[obj.ref];
|
||||||
|
|
||||||
|
// Remove existing relationship because only one file
|
||||||
|
// can be related to this field.
|
||||||
|
if (association.nature === 'manyMorphToOne') {
|
||||||
|
return virtualFields.push(
|
||||||
|
module.exports.removeRelationMorph.call(this, {
|
||||||
|
alias: association.alias,
|
||||||
|
ref: model.collectionName,
|
||||||
|
refId: obj.refId,
|
||||||
|
field: obj.field
|
||||||
|
})
|
||||||
|
.then(() =>
|
||||||
|
module.exports.addRelationMorph.call(this, {
|
||||||
|
id: response[this.primaryKey],
|
||||||
|
alias: association.alias,
|
||||||
|
ref: model.collectionName,
|
||||||
|
refId: obj.refId,
|
||||||
|
field: obj.field
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
virtualFields.push(module.exports.addRelationMorph.call(this, {
|
virtualFields.push(module.exports.addRelationMorph.call(this, {
|
||||||
id: response[this.primaryKey],
|
id: response[this.primaryKey],
|
||||||
alias: association.alias,
|
alias: association.alias,
|
||||||
@ -386,12 +408,12 @@ module.exports = {
|
|||||||
|
|
||||||
removeRelationMorph: async function (params) {
|
removeRelationMorph: async function (params) {
|
||||||
return await this.morph.forge()
|
return await this.morph.forge()
|
||||||
.where({
|
.where(_.omitBy({
|
||||||
[`${this.collectionName}_id`]: params.id,
|
[`${this.collectionName}_id`]: params.id,
|
||||||
[`${params.alias}_id`]: params.refId,
|
[`${params.alias}_id`]: params.refId,
|
||||||
[`${params.alias}_type`]: params.ref,
|
[`${params.alias}_type`]: params.ref,
|
||||||
field: params.field
|
field: params.field
|
||||||
})
|
}, _.isEmpty))
|
||||||
.destroy();
|
.destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user