How to use the inflection.foreign_key function in inflection

To help you get started, we’ve selected a few inflection 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 wearevolt / mobx-model / src / set_relations_defaults.js View on Github external
}

    // json key for embedded json
    if (!relation.jsonKey) {
      relation.jsonKey = underscore(relation.propertyName);
    }

    // key in top level json
    if (!relation.topLevelJsonKey) {
      relation.topLevelJsonKey = tableize(relation.propertyName);
    }

    // foreign key with ids of relations
    if (!relation.foreignKey) {
      if (relation.isHasMany) {
        relation.foreignKey = foreign_key(singularize(relation.propertyName)) + 's';
      } else if (relation.isHasOne) {
        relation.foreignKey = foreign_key(relation.propertyName);
      }
    }

    let name = upperCaseFirstLetter(relation.propertyName);
    if (relation.isHasMany) name = singularize(name);

    // method name to add single relation, will be used as alias
    if (!relation.setMethodName) {      
      relation.setMethodName = `set${name}`;
    }

    // method name to remove single relation, will be used as alias
    if (!relation.removeMethodName) {
      relation.removeMethodName = `remove${name}`;
github wearevolt / mobx-model / src / set_relations_defaults.js View on Github external
// json key for embedded json
    if (!relation.jsonKey) {
      relation.jsonKey = underscore(relation.propertyName);
    }

    // key in top level json
    if (!relation.topLevelJsonKey) {
      relation.topLevelJsonKey = tableize(relation.propertyName);
    }

    // foreign key with ids of relations
    if (!relation.foreignKey) {
      if (relation.isHasMany) {
        relation.foreignKey = foreign_key(singularize(relation.propertyName)) + 's';
      } else if (relation.isHasOne) {
        relation.foreignKey = foreign_key(relation.propertyName);
      }
    }

    let name = upperCaseFirstLetter(relation.propertyName);
    if (relation.isHasMany) name = singularize(name);

    // method name to add single relation, will be used as alias
    if (!relation.setMethodName) {      
      relation.setMethodName = `set${name}`;
    }

    // method name to remove single relation, will be used as alias
    if (!relation.removeMethodName) {
      relation.removeMethodName = `remove${name}`;
    }