How to use the ember-cli-mirage/utils/inflector.pluralize function in ember-cli-mirage

To help you get started, we’ve selected a few ember-cli-mirage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miragejs / ember-cli-mirage / tests / integration / orm / has-many / has-many-helper.js View on Github external
newParentNewChildren() {
    let user = this.schema[pluralize(this.ownModel)].new();
    let newHomeAddress = user[`new${singularize(capitalize(this.ownKey))}`]();

    return [user, [newHomeAddress]];
  }
github miragejs / ember-cli-mirage / tests / integration / orm / has-many / has-many-helper.js View on Github external
savedParentMixedChildren() {
    let insertedUser = this.db[pluralize(this.ownModel)].insert({ name: 'Link' });
    let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way', [`${camelize(this.otherKey)}Id`]: insertedUser.id });

    let user = this.schema[pluralize(this.ownModel)].find(insertedUser.id);
    let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
    let newHomeAddress = user[`new${singularize(capitalize(this.ownKey))}`]();

    return [user, [savedHomeAddress, newHomeAddress]];
  }
github miragejs / ember-cli-mirage / tests / integration / orm / has-many / has-many-helper.js View on Github external
newParentNoChildren() {
    let user = this.schema[pluralize(this.ownModel)].new();

    return [user, []];
  }
github miragejs / ember-cli-mirage / tests / integration / orm / has-many / has-many-helper.js View on Github external
newParentSavedChildren() {
    let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way' });
    let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
    let newUser = this.schema[pluralize(this.ownModel)].new({ [this.ownKey]: [savedHomeAddress] });

    return [newUser, [savedHomeAddress]];
  }
github miragejs / ember-cli-mirage / tests / integration / orm / has-many / has-many-helper.js View on Github external
newParentMixedChildren() {
    let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way' });
    let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
    let newHomeAddress = this.schema[pluralize(this.otherModel)].new();

    let newUser = this.schema[pluralize(this.ownModel)].new({ [this.ownKey]: [savedHomeAddress, newHomeAddress] });

    return [newUser, [savedHomeAddress, newHomeAddress]];
  }
github miragejs / ember-cli-mirage / tests / integration / orm / has-many / has-many-helper.js View on Github external
newParentSavedChildren() {
    let insertedHomeAddress = this.db[pluralize(this.otherModel)].insert({ name: '123 Hyrule Way' });
    let savedHomeAddress = this.schema[pluralize(this.otherModel)].find(insertedHomeAddress.id);
    let newUser = this.schema[pluralize(this.ownModel)].new({ [this.ownKey]: [savedHomeAddress] });

    return [newUser, [savedHomeAddress]];
  }
github cowboyd / mirage-server / addon / route-handlers / shorthands / post.js View on Github external
handleStringShorthand(string, dbOrSchema, request) {
    let type = string;
    let collection = pluralize(string);
    let attrs = this._getAttrsForRequest(request);

    if (dbOrSchema instanceof Db) {
      let db = dbOrSchema;
      if (!db[collection]) {
        console.error("Mirage: The route handler for " + request.url + " is trying to insert data into the " + collection + " collection, but that collection doesn't exist. To create it, create an empty fixture file or factory.");
      }

      let model = db[collection].insert(attrs);

      let response = {};
      response[type] = model;

      return response;

    } else {
github kloeckner-i / ember-cli-mirage-graphql / addon / related-records.js View on Github external
function lookUpRelatedRecords(db, fieldName, isList, record, type) {
  let relatedTable = isList ? fieldName : pluralize(fieldName);
  let relatedRecords = filterRelatedByRecord(db[relatedTable], record, type);

  return isList ? relatedRecords : relatedRecords[0];
}
github kloeckner-i / ember-cli-mirage-graphql / addon / mock.js View on Github external
const mockFn = (db, varsMap, fieldsMap = {}) => (root, vars, _, meta = {}) => {
  let isList = getIsList(meta);
  let type = getTypeFromMeta(meta, isList);
  let { _fields: fields } = type;
  let typeName = camelize(type.name);
  let records = db[pluralize(typeName)];

  records = filterRecordsByVars(records, vars, varsMap[type]);
  records = getRelatedRecords(records, typeName, fields, fieldsMap[type], db);
  records = filterRecordsByMappedField(records, meta.fieldName, fieldsMap);

  return isList ? records : records[0];
};