Validates model relations naming. If any relation has same alias with any column and/or relation, this function
returns description of the error as string.
@private
@param {Object} templateTable -
@param {Object} relation -
335577
function validateNaming(templateTable) {
    var ri, ci, pi, relationToValidate, column, catched, relation, duplicates = [];

    for (ri = 0; ri < templateTable.relations.length; ri = ri + 1) {
        relationToValidate = templateTable.relations[ri];

        // Check against columns
        for (ci = 0, catched = false; ci < templateTable.columns.length && !catched; ci = ci + 1) {
            column = templateTable.columns[ci];
            if (column.name === relationToValidate.as) {
                logger.warn('ERROR: %s is already used. %s relation is trying to have alias of previously defined column with same name in table %s.%s.', relationToValidate.as, relationToValidate.type, templateTable.schema, templateTable.tableName);
                duplicates.push(relationToValidate.as);
                catched = true;
            }
        }

        // Check against previous relations. Later realitons will check against this already.
        for (pi = 0, catched = false; pi < ri && !catched; pi = pi + 1) {
            relation = templateTable.relations[pi];
            if (relation.as === relationToValidate.as) {
                logger.warn('ERROR: %s is already used. %s relation is trying to have alias of previously defined %s relation in table %s.%s.', relationToValidate.as, relationToValidate.type, relation.type, templateTable.schema, templateTable.tableName);
                duplicates.push(relationToValidate.as);
                catched = true;
            }
        }
    }

    if (duplicates.length > 0) {
        return 'Table ' + templateTable.schema + '.' + templateTable.tableName + ' has duplicate relation aliases: ' + duplicates.join(',') + '.';
    }

}
1185770
public function relationIsJoined($relation)
    {
        if ($this->_joinedTables === null) {
            $this->_joinedTables = $this->getJoinedTables();
        }

        return in_array($this->getRelatedTable($relation), $this->_joinedTables, true);
    }
669595
function makerelation (model, relation) {
	let options = {
		as: relation.As,
		foreignKey: relation.key
	};
	let target = exp.databases[inflector.pluralize(relation.Children)];
	if (relation.Rel !== 'manyToMany') {
		exp.databases[model][relation.Rel](target, options);
	} else {
		exp.databases[model].prototype.many2many = exp.databases[model].prototype.many2many || {};
		exp.databases[model].prototype.many2many[relation.Parent] = function (id, id2) {
			if (id && id2) {
				return exp.databases[relation.Children].findcre({
					[`${model}ID`]: id,
					[`${relation.Parent}ID`]: id2
				});
			}
			return exp.databases[relation.Children].find({
				where: {
					[`${model}ID`]: id
				}
			}).then(records => {
				let all = [];
				for (const record of records) {
					all.push(exp.databases[relation.Parent].findById(record[`${relation.Parent}ID`]));
				}
				return Promise.all(all);
			});
		};
	}
}
352456
@JsonCreator
	public static StringLinkRelation of(String relation) {

		Assert.hasText(relation, "Relation must not be null or empty!");

		return CACHE.computeIfAbsent(relation, StringLinkRelation::new);
	}
570263
function createRelation(model, relationName, data) {
  if (!model) {
    throw new Error('No model provided.');
  }
  return _transact2['default'](model, function (transaction) {
    var existing = _related2['default'](model, relationName).map(function (rel) {
      return {
        id: _id2['default'](rel),
        type: _type2['default'](rel)
      };
    });
    var all = data.concat(existing);
    // TODO: should i be doing a deep comparison instead?
    var unique = _lodash2['default'].uniq(all, JSON.stringify.bind(null));
    return _relate2['default'](model, {
      name: relationName,
      data: unique
    }, 'add', transaction);
  });
}
110114
public static void assertTrueOrInvalidPropertyName(boolean expression, SQLProperty item1, SQLProperty item2) {
		if (!expression) {
			String msg = String.format("Properties '%s#%s' and '%s#%s' must have same column name",
					item1.getParent().name, item1.name, item2.getParent().name, item2.name);
			throw (new InvalidPropertyToColumnConversion(msg));
		}

	}
716070
def _nested_relations(self, relation):
        
        nested = {}

        for name, constraints in self._eager_load.items():
            if self._is_nested(name, relation):
                nested[name[len(relation + ".") :]] = constraints

        return nested
464099
def has_many(relation_name, *all_args)
      # rubocop:enable Style/PredicateName

      args = all_args.pop

      relation = {
        type: :has_many,
        relation_name: relation_name,
        table_name: args[:table_name] || relation_name,
        args: args,
        all_args: all_args
      }

      if args[:foreign_key]
        relation[:foreign_key] = args.fetch(:foreign_key)
      else
        relation[:foreign_key] = :"#{StringCases.camel_to_snake(name)}_id"
      end

      relation[:dependent] = args.fetch(:dependent) if args[:dependent]

      if args && args[:class_name]
        relation[:class_name] = args.fetch(:class_name)
      else
        relation[:class_name] = StringCases.snake_to_camel(StringCases.singularize(relation_name))
      end

      @has_many_relations ||= []
      @has_many_relations << relation

      @relationships ||= {}
      @relationships[relation_name] = relation

      define_method(relation_name) do
        class_instance = StringCases.constantize(relation.fetch(:class_name))
        query = class_instance.where(relation.fetch(:foreign_key) => id)
        query.previous_model = self
        query.relation = relation

        all_args.each do |arg|
          query = query.instance_exec(&arg) if arg.is_a?(Proc)
        end

        query
      end
    end
1372296
function scopeRemoting (scopeName, scope, define) {
  var pathName = (scope.options &&
    scope.options.http &&
    scope.options.http.path) ||
    scopeName
  var isStatic = scope.isStatic
  var toModelName = scope.modelTo.modelName

  // https://github.com/strongloop/loopback/issues/811
  // Check if the scope is for a hasMany relation
  var relation = this.relations[scopeName]

  if (relation && relation.modelTo) {
    // For a relation with through model, the toModelName should be the one
    // from the target model
    toModelName = relation.modelTo.modelName
  }

  define('__get__' + scopeName, {
    isStatic: isStatic,
    accessType: 'READ',
    description: 'Queries ' + scopeName + ' of ' + this.modelName + '.',
    http: {
      verb: 'get',
      path: '/' + pathName
    },
    accepts: {
      arg: 'filter',
      type: 'object'
    },
    returns: {
      arg: scopeName,
      type: [toModelName],
      root: true
    }
  })
}
1069377
private void validateRelationship(String baseTableName,
			String relatedTableName, String relationName) {

		// Verify the base and related tables exist
		if (!geoPackage.isTable(baseTableName)) {
			throw new GeoPackageException(
					"Base Relationship table does not exist: " + baseTableName
							+ ", Relation: " + relationName);
		}
		if (!geoPackage.isTable(relatedTableName)) {
			throw new GeoPackageException(
					"Related Relationship table does not exist: "
							+ relatedTableName + ", Relation: " + relationName);
		}

		// Verify spec defined relation types
		RelationType relationType = RelationType.fromName(relationName);
		if (relationType != null) {
			validateRelationship(baseTableName, relatedTableName, relationType);
		}

	}
787255
function(relationshipModelName, kind) {
    var key = decamelize(relationshipModelName);
    if (kind === "belongsTo") {
      return key + "_id";
    } else if (kind === "hasMany") {
      return singularize(key) + "_ids";
    } else {
      return key;
    }
  }
259289
function parseIncludes(field, fieldName, modelName, parent) {
		// check all attributes are strings and valid fields
		if (!field.attributes) {
			field.attributes = [];
		} else {
			if (!Array.isArray(field.attributes)) field.attributes = [field.attributes];

			_.forEach(field.attributes, function(attribute) {
				if (!_.isString(attribute)) throw new Sequelize.VirtualFieldsError("Attribute of virtual field '" + modelName + "'.'" + fieldName + "' is not a string");

				if (!parent.attributes[attribute]) throw new Sequelize.VirtualFieldsError("Attribute of virtual field '" + modelName + "'.'" + fieldName + "' refers to a nonexistent field '" + parent.name + "'.'" + attribute + "'");
			});
		}

		// format includes as {model: model, as: as} and convert strings to models
		if (field.include) {
			if (!Array.isArray(field.include)) field.include = [field.include];

			_.forEach(field.include, function(include, index) {
				include = parseClause(field.include, index, 'Include', modelName, fieldName, parent);

				parseIncludes(include, fieldName, modelName, include.model);
			});
		}
	}
894146
public function determineValidationRules(ModelRelationData $relation, ModelFormFieldData $field)
    {
        $rules = [];

        if ($field->required() && ! $field->translated()) {
            $rules[] = 'required';
        } else {
            // Anything that is not required should by default be explicitly nullable
            // since Laravel 5.4.
            $rules[] = 'nullable';
        }

        // todo
        // make validation rules as far as possible, based on the key type (incrementing?)
        // or using exists:: ...

        return $rules;
    }
390533
private function isRelationForeignKeyNullable(Relation $relation)
    {
        $reflectionObj = new \ReflectionObject($relation);
        if (!$reflectionObj->hasProperty('foreignKey')) {
            return false;
        }
        $fkProp = $reflectionObj->getProperty('foreignKey');
        $fkProp->setAccessible(true);

        return isset($this->nullableColumns[$fkProp->getValue($relation)]);
    }
1095728
def relation_column(instance, fields):
    '''
    
    '''
    relation = getattr(instance.__class__, fields[0]).property
    _field = getattr(instance, fields[0])
    if relation.lazy == 'dynamic':
        _field = _field.first()
    return getattr(_field, fields[1]) if _field else ''
706464
function hasOneRemoting (relationName, relation, define) {
  var pathName = (relation.options.http && relation.options.http.path) ||
    relationName
  var toModelName = relation.modelTo.modelName

  define('__get__' + relationName, {
    isStatic: false,
    accessType: 'READ',
    description: 'Fetches hasOne relation ' + relationName + '.',
    http: {
      verb: 'get',
      path: '/' + pathName
    },
    accepts: {
      arg: 'refresh',
      type: 'boolean',
      http: {
        source: 'query'
      }
    },
    returns: {
      arg: relationName,
      type: relation.modelTo.modelName,
      root: true
    }
  })

  var findHasOneRelationshipsFunc = function (cb) {
    this['__get__' + pathName](cb)
  }

  define(
    '__findRelationships__' + relationName,
    {
      isStatic: false,
      accessType: 'READ',
      description: 'Find relations for ' + relationName + '.',
      http: {
        verb: 'get',
        path: '/relationships/' + pathName
      },
      returns: {
        arg: 'result',
        type: toModelName,
        root: true
      }
    },
    findHasOneRelationshipsFunc
  )
}
373901
function replaceTableNames(sql, identifiers, sequelize) {
	const {queryInterface} = sequelize;
	_.forIn(identifiers, (model, identifier) => {
		const tableName = model.getTableName();
		sql = sql.replace(
			new RegExp(`\\*${identifier}(?![a-zA-Z0-9_])`, 'g'),
			tableName.schema ? tableName.toString() : queryInterface.quoteIdentifier(tableName)
		);
	});
	return sql;
}