lithium\data\model\Relationship::_strategies()
Strategies used to query related objects, indexed by key.
Source
protected function _strategies() {
return [
static::LINK_EMBEDDED => function($object, $relationship) {
$fieldName = $relationship->fieldName();
return $object->{$fieldName};
},
static::LINK_CONTAINED => function($object, $relationship) {
$isArray = ($relationship->type() === "hasMany");
return $isArray ? $object->parent()->parent() : $object->parent();
},
static::LINK_KEY => function($object, $relationship, $options) {
$model = $relationship->to();
if (!$query = $relationship->query($object)) {
return;
}
$method = ($relationship->type() === "hasMany") ? 'all' : 'first';
return $model::$method(Set::merge((array) $query, (array) $options));
},
static::LINK_KEY_LIST => function($object, $relationship, $options) {
$model = $relationship->to();
$query = $relationship->query($object);
return $model::all(Set::merge($query, $options));
}
];
}