lithium\data\Model::bind()
Creates a relationship binding between this model and another.
Parameters
-
string
$type
The type of relationship to create. Must be one of
'hasOne'
,'hasMany'
or'belongsTo'
. -
string
$name
The name of the relationship. If this is also the name of the model, the model must be in the same namespace as this model. Otherwise, the fully-namespaced path to the model class must be specified in
$config
. -
array
$config
Any other configuration that should be specified in the relationship. See the
Relationship
class for more information.
Returns
objectReturns an instance of the Relationship
class that defines the connection.
Source
public static function bind($type, $name, array $config = []) {
$self = static::object();
if (!isset($config['fieldName'])) {
$config['fieldName'] = $self->_relationFieldName($type, $name);
}
if (!in_array($type, $self->_relationTypes)) {
throw new ConfigException("Invalid relationship type `{$type}` specified.");
}
$self->_relationFieldNames[$config['fieldName']] = $name;
$rel = static::connection()->relationship(get_called_class(), $type, $name, $config);
return $self->_relations[$name] = $rel;
}