mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 17:37:26 +00:00
Fix relation table creation
This commit is contained in:
parent
8adc8ec200
commit
d986cb4cc8
@ -487,17 +487,38 @@ module.exports = function(strapi) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (manyRelations && manyRelations.dominant) {
|
if (manyRelations && manyRelations.dominant) {
|
||||||
|
const collection = manyRelations.plugin ?
|
||||||
|
strapi.plugins[manyRelations.plugin].models[manyRelations.collection]:
|
||||||
|
strapi.models[manyRelations.collection];
|
||||||
|
|
||||||
const attributes = {
|
const attributes = {
|
||||||
[`${pluralize.singular(manyRelations.collection)}_id`]: {
|
[`${pluralize.singular(manyRelations.collection)}_id`]: {
|
||||||
type: 'integer'
|
type: 'integer'
|
||||||
},
|
},
|
||||||
[`${pluralize.singular(manyRelations.via)}_id`]: {
|
[`${pluralize.singular(definition.globalId.toLowerCase())}_id`]: {
|
||||||
type: 'integer'
|
type: 'integer'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const keys = [pluralize.plural(manyRelations.collection), pluralize.plural(manyRelations.via)];
|
const table = _.get(manyRelations, 'collectionName') ||
|
||||||
const table = [keys.join('_'), keys.reverse().join('_')].join('__');
|
_.map(
|
||||||
|
_.sortBy(
|
||||||
|
[
|
||||||
|
collection.attributes[
|
||||||
|
manyRelations.via
|
||||||
|
],
|
||||||
|
manyRelations
|
||||||
|
],
|
||||||
|
'collection'
|
||||||
|
),
|
||||||
|
table => {
|
||||||
|
return _.snakeCase(
|
||||||
|
pluralize.plural(table.collection) +
|
||||||
|
' ' +
|
||||||
|
pluralize.plural(table.via)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
).join('__');
|
||||||
|
|
||||||
await handler(table, attributes);
|
await handler(table, attributes);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1 @@
|
|||||||
{
|
{}
|
||||||
"article": {
|
|
||||||
"attributes": {
|
|
||||||
"title": {
|
|
||||||
"appearance": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user