mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Update models attributes & get models from the database manager
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
parent
f10f51f372
commit
8a69d187d0
@ -7,7 +7,7 @@
|
||||
"attributes": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"minLength": 3,
|
||||
"minLength": 1,
|
||||
"unique": true,
|
||||
"configurable": false,
|
||||
"required": true
|
||||
|
||||
@ -8,18 +8,20 @@
|
||||
"firstname": {
|
||||
"type": "string",
|
||||
"unique": false,
|
||||
"minLength": 1,
|
||||
"configurable": false,
|
||||
"required": false
|
||||
},
|
||||
"lastname": {
|
||||
"type": "string",
|
||||
"unique": false,
|
||||
"minLength": 1,
|
||||
"configurable": false,
|
||||
"required": false
|
||||
},
|
||||
"username": {
|
||||
"type": "string",
|
||||
"unique": true,
|
||||
"unique": false,
|
||||
"configurable": false,
|
||||
"required": false
|
||||
},
|
||||
|
||||
@ -138,11 +138,7 @@ module.exports = ({ models, target }, ctx) => {
|
||||
|
||||
// Exclude polymorphic association.
|
||||
if (globalName !== '*') {
|
||||
globalId = details.plugin
|
||||
? details.plugin === 'admin'
|
||||
? _.get(strapi.admin, `models.${globalName.toLowerCase()}.globalId`)
|
||||
: _.get(strapi.plugins, `${details.plugin}.models.${globalName.toLowerCase()}.globalId`)
|
||||
: _.get(strapi.models, `${globalName.toLowerCase()}.globalId`);
|
||||
globalId = strapi.db.getModel(globalName.toLowerCase(), details.plugin).globalId;
|
||||
}
|
||||
|
||||
switch (verbose) {
|
||||
|
||||
@ -120,6 +120,14 @@ class DatabaseManager {
|
||||
});
|
||||
}
|
||||
|
||||
getModelsByPluginName(pluginName) {
|
||||
if (!pluginName) {
|
||||
return strapi.models;
|
||||
}
|
||||
|
||||
return pluginName === 'admin' ? strapi.admin.models : strapi.plugins[pluginName].models;
|
||||
}
|
||||
|
||||
getReservedNames() {
|
||||
return {
|
||||
models: constants.RESERVED_MODEL_NAMES,
|
||||
|
||||
@ -38,11 +38,7 @@ module.exports = {
|
||||
other: '',
|
||||
};
|
||||
|
||||
const models = attribute.plugin
|
||||
? attribute.plugin === 'admin'
|
||||
? strapi.admin.models
|
||||
: strapi.plugins[attribute.plugin].models
|
||||
: strapi.models;
|
||||
const models = strapi.db.getModelsByPluginName(attribute.plugin);
|
||||
|
||||
const pluginModels = Object.values(strapi.plugins).reduce((acc, plugin) => {
|
||||
return acc.concat(Object.values(plugin.models));
|
||||
@ -326,15 +322,8 @@ module.exports = {
|
||||
});
|
||||
|
||||
if (targetName !== '*') {
|
||||
if (association.plugin) {
|
||||
const models =
|
||||
association.plugin === 'admin'
|
||||
? strapi.admin.models
|
||||
: strapi.plugins[association.plugin].models || {};
|
||||
details = _.get(models, [targetName, 'attributes', association.via]);
|
||||
} else {
|
||||
details = _.get(strapi.models, [targetName, 'attributes', association.via], {});
|
||||
}
|
||||
const models = strapi.db.getModelsByPluginName(association.plugin);
|
||||
details = _.get(models, [targetName, 'attributes', association.via], {});
|
||||
}
|
||||
|
||||
// Build associations object
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user