Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getAssociationModel(associationName) {
var schema = Schemas.schemas[model.collection.name];
var field = _.findWhere(schema.fields, { field: associationName });
if (field && field.reference) {
var referenceName = field.reference.split('.')[0];
return Inflector.camelize(Inflector.singularize(referenceName));
}
}
controllers.forEach(controller => {
const reflexMethodName = reflex.split('#')[1]
const specificLifecycleMethodName = ['before', 'after'].includes(stage)
? `${stage}${camelize(reflexMethodName)}`
: `${camelize(reflexMethodName, false)}${camelize(stage)}`
const specificLifecycleMethod = controller[specificLifecycleMethodName]
const genericLifecycleMethodName = ['before', 'after'].includes(stage)
? `${stage}Reflex`
: `reflex${camelize(stage)}`
const genericLifecycleMethod = controller[genericLifecycleMethodName]
if (typeof specificLifecycleMethod === 'function') {
setTimeout(
() =>
specificLifecycleMethod.call(
controller,
element,
reflex,
element.reflexError
),
1
)
}
if (typeof genericLifecycleMethod === 'function') {
getForeignKey() {
return `${camelize(this.key)}Id`;
}
keyForModel(modelName) {
return camelize(modelName);
}
keyForPolymorphicForeignKeyType(relationshipName) {
return `${camelize(relationshipName)}Type`;
}
Object.keys(json.data.relationships).forEach((key) => {
let relationship = json.data.relationships[key];
if (Array.isArray(relationship.data)) {
attrs[`${camelize(singularize(key))}Ids`] = relationship.data.map(rel => rel.id);
} else {
attrs[`${camelize(key)}Id`] = relationship.data && relationship.data.id;
}
}, {});
}
modelClassFor(modelName) {
return this._registry[camelize(modelName)].class.prototype;
}
handleStringShorthand(request, modelClass) {
let modelName = this.shorthand;
let camelizedModelName = camelize(modelName);
assert(
modelClass,
`The route handler for ${request.url} is trying to access the ${camelizedModelName} model, but that model doesn't exist. Create it using 'ember g mirage-model ${modelName}'.`
);
let id = this._getIdForRequest(request);
if (id) {
let model = modelClass.find(id);
if (!model) {
return new Response(404);
} else {
return new Response(204);
}
} else if (this.options.coalesce && request.queryParams && request.queryParams.ids) {
let model = modelClass.find(request.queryParams.ids);
_modelFor(modelName) {
return this._registry[camelize(modelName)].class;
}
export function camelize(str: string): string {
return inflected.camelize(str);
}