@sap/cds-compiler
Version:
CDS (Core Data Services) compiler and backends
29 lines (25 loc) • 974 B
JavaScript
;
const { applyTransformationsOnNonDictionary } = require('../model/csnUtils');
/**
* Check for nested projections (expand) on to-many associations or compositions.
* Nested projections are only valid for to-one relationships.
*
* @param {object} parent Object with the expression as a property
* @param {string} propOnParent Name of the expression property on parent
* @param {Array} _e Expression to check (unused)
* @param {CSN.Path} path
*/
function expandToMany( parent, propOnParent, _e, path ) {
applyTransformationsOnNonDictionary(parent, propOnParent, {
expand: (_parent, _prop, _expand, _path) => {
const last = _parent._links?.at(-1).art;
if (last?.cardinality && last.cardinality.max !== 1) {
this.message('ref-unexpected-many-expand', _path,
{ '#': last.type === 'cds.Composition' ? 'composition' : 'std' });
}
},
}, null, path);
}
module.exports = {
columns: expandToMany,
};