strapi/packages/core/utils/lib/relations.js

18 lines
442 B
JavaScript
Raw Normal View History

2020-12-01 16:38:47 +01:00
'use strict';
2020-12-18 11:24:52 +01:00
const { prop } = require('lodash/fp');
2020-12-01 16:38:47 +01:00
const MANY_RELATIONS = ['oneToMany', 'manyToMany', 'manyWay'];
2020-12-18 11:24:52 +01:00
const RF_RELATIONS = ['oneToMany', 'manyToMany', 'manyWay', 'manyToOne', 'oneWay', 'oneToOne'];
const getRelationalFields = modelDef => {
return modelDef.associations.filter(a => RF_RELATIONS.includes(a.nature)).map(prop('alias'));
};
2020-12-01 16:38:47 +01:00
module.exports = {
2020-12-18 11:24:52 +01:00
getRelationalFields,
2020-12-16 15:28:11 +01:00
constants: {
MANY_RELATIONS,
},
2020-12-01 16:38:47 +01:00
};