Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof type === 'object') {
options = type;
type = undefined;
}
assert(
`The first argument to hasMany must be a string representing a model type key, not an instance of ${inspect(
type
)}. E.g., to define a relation to the Comment model, use hasMany('comment')`,
typeof type === 'string' || typeof type === 'undefined'
);
options = options || {};
if (typeof type === 'string') {
type = normalizeModelName(type);
}
// Metadata about relationships is stored on the meta of
// the relationship. This is used for introspection and
// serialization. Note that `key` is populated lazily
// the first time the CP is called.
let meta = {
type,
options,
isRelationship: true,
kind: 'hasMany',
name: 'Has Many',
key: null,
};
return computed({
modelNameFromPayloadKey(key) {
return singularize(normalizeModelName(key));
},
function belongsTo(modelName, options) {
let opts, userEnteredModelName;
if (typeof modelName === 'object') {
opts = modelName;
userEnteredModelName = undefined;
} else {
opts = options;
userEnteredModelName = modelName;
}
if (typeof userEnteredModelName === 'string') {
userEnteredModelName = normalizeModelName(userEnteredModelName);
}
assert(
'The first argument to belongsTo must be a string representing a model type key, not an instance of ' +
inspect(userEnteredModelName) +
". E.g., to define a relation to the Person model, use belongsTo('person')",
typeof userEnteredModelName === 'string' || typeof userEnteredModelName === 'undefined'
);
opts = opts || {};
let meta = {
type: userEnteredModelName,
isRelationship: true,
options: opts,
kind: 'belongsTo',
isPrimaryType(store, modelName, primaryModelClass) {
return normalizeModelName(modelName) === primaryModelClass.modelName;
},
modelNameFromPayloadKey(key) {
return singularize(normalizeModelName(key));
},
modelNameFromPayloadKey(key) {
return normalizeModelName(key);
},