Extends
lithium\data\Source
Document relationships.
Parameters
- string $class
- string $type Relationship type, e.g. `belongsTo`.
- string $name
- array $config
Returns
arraySource
public function relationship($class, $type, $name, array $config = array()) {
$key = Inflector::camelize($type == 'belongsTo' ? $class::meta('name') : $name, false);
$config += compact('name', 'type', 'key');
$config['from'] = $class;
$relationship = $this->_classes['relationship'];
$defaultLinks = array(
'hasOne' => $relationship::LINK_EMBEDDED,
'hasMany' => $relationship::LINK_EMBEDDED,
'belongsTo' => $relationship::LINK_CONTAINED
);
$config += array('link' => $defaultLinks[$type]);
return new $relationship($config);
}