lithium\data\model\Relationship::embed()
Fetch data related to a whole collection and embed the result in it.
Parameters
-
mixed
$collection
A collection of data.
-
array
$options
The embed query options.
Returns
mixedThe fetched data.
Source
public function embed(&$collection, $options = []) {
$keys = $this->key();
if (count($keys) !== 1) {
throw new Exception("The embedding doesn't support composite primary key.");
}
switch($this->type()) {
case 'belongsTo';
return $this->_embedBelongsTo($collection, $options);
case 'hasMany';
if ($this->link() === static::LINK_KEY_LIST) {
return $this->_embedHasManyAsList($collection, $options);
}
return $this->_embedHasMany($collection, $options);
case 'hasOne';
return $this->_embedHasOne($collection, $options);
default:
throw new Exception("Error {$this->type()} is unsupported ");
}
}