mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +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": {
|
"attributes": {
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 3,
|
"minLength": 1,
|
||||||
"unique": true,
|
"unique": true,
|
||||||
"configurable": false,
|
"configurable": false,
|
||||||
"required": true
|
"required": true
|
||||||
|
|||||||
@ -8,18 +8,20 @@
|
|||||||
"firstname": {
|
"firstname": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"unique": false,
|
"unique": false,
|
||||||
|
"minLength": 1,
|
||||||
"configurable": false,
|
"configurable": false,
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
"lastname": {
|
"lastname": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"unique": false,
|
"unique": false,
|
||||||
|
"minLength": 1,
|
||||||
"configurable": false,
|
"configurable": false,
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
"username": {
|
"username": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"unique": true,
|
"unique": false,
|
||||||
"configurable": false,
|
"configurable": false,
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
|
|||||||
@ -138,11 +138,7 @@ module.exports = ({ models, target }, ctx) => {
|
|||||||
|
|
||||||
// Exclude polymorphic association.
|
// Exclude polymorphic association.
|
||||||
if (globalName !== '*') {
|
if (globalName !== '*') {
|
||||||
globalId = details.plugin
|
globalId = strapi.db.getModel(globalName.toLowerCase(), details.plugin).globalId;
|
||||||
? 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`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (verbose) {
|
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() {
|
getReservedNames() {
|
||||||
return {
|
return {
|
||||||
models: constants.RESERVED_MODEL_NAMES,
|
models: constants.RESERVED_MODEL_NAMES,
|
||||||
|
|||||||
@ -38,11 +38,7 @@ module.exports = {
|
|||||||
other: '',
|
other: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const models = attribute.plugin
|
const models = strapi.db.getModelsByPluginName(attribute.plugin);
|
||||||
? attribute.plugin === 'admin'
|
|
||||||
? strapi.admin.models
|
|
||||||
: strapi.plugins[attribute.plugin].models
|
|
||||||
: strapi.models;
|
|
||||||
|
|
||||||
const pluginModels = Object.values(strapi.plugins).reduce((acc, plugin) => {
|
const pluginModels = Object.values(strapi.plugins).reduce((acc, plugin) => {
|
||||||
return acc.concat(Object.values(plugin.models));
|
return acc.concat(Object.values(plugin.models));
|
||||||
@ -326,15 +322,8 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (targetName !== '*') {
|
if (targetName !== '*') {
|
||||||
if (association.plugin) {
|
const models = strapi.db.getModelsByPluginName(association.plugin);
|
||||||
const models =
|
details = _.get(models, [targetName, 'attributes', association.via], {});
|
||||||
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], {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build associations object
|
// Build associations object
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user