Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Document DboSource::getConstraint().

Also, update the function signature (to be compliant with other
functions) and type hint $LinkModel.
  • Loading branch information...
commit c5c8cb80ba86c9f61976bd4e388659ba25ea0185 1 parent a7ecf44
@bar bar authored
Showing with 37 additions and 35 deletions.
  1. +37 −35 lib/Cake/Model/Datasource/DboSource.php
View
72 lib/Cake/Model/Datasource/DboSource.php
@@ -1711,51 +1711,53 @@ public function generateAssociationQuery(Model $Model, Model $LinkModel, $type,
}
/**
- * Returns a conditions array for the constraint between two models
+ * Returns a conditions array for the constraint between two models.
*
- * @param string $type Association type
- * @param Model $Model Model object
- * @param string $linkModel
- * @param string $alias
- * @param array $assoc
- * @param string $alias2
- * @return array Conditions array defining the constraint between $Model and $association
+ * @param string $type Association type.
+ * @param Model $Model Primary Model object.
+ * @param Model $LinkModel Linked model object.
+ * @param string $association Association name.
+ * @param array $assocData Association data.
+ * @param string $association2 HABTM association name.
+ * @return array Conditions array defining the constraint between $Model and $LinkModel.
*/
- public function getConstraint($type, Model $Model, $linkModel, $alias, $assoc, $alias2 = null) {
- $assoc += array('external' => false);
+ public function getConstraint($type, Model $Model, Model $LinkModel, $association, $assocData, $association2 = null) {
+ $assocData += array('external' => false);
- if (empty($assoc['foreignKey'])) {
+ if (empty($assocData['foreignKey'])) {
return array();
}
- switch (true) {
- case ($type === 'hasOne' && $assoc['external']):
- return array(
- "{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'
- );
- case ($type === 'hasOne' && !$assoc['external']):
- return array(
- "{$alias}.{$assoc['foreignKey']}" => $this->identifier("{$Model->alias}.{$Model->primaryKey}")
- );
- case ($type === 'belongsTo' && $assoc['external']):
- return array(
- "{$alias}.{$linkModel->primaryKey}" => '{$__cakeForeignKey__$}'
- );
- case ($type === 'belongsTo' && !$assoc['external']):
- return array(
- "{$Model->alias}.{$assoc['foreignKey']}" => $this->identifier("{$alias}.{$linkModel->primaryKey}")
- );
- case ($type === 'hasMany'):
- return array(
- "{$alias}.{$assoc['foreignKey']}" => array('{$__cakeID__$}')
- );
- case ($type === 'hasAndBelongsToMany'):
+ switch ($type) {
+ case 'hasOne':
+ if ($assocData['external']) {
+ return array(
+ "{$association}.{$assocData['foreignKey']}" => '{$__cakeID__$}'
+ );
+ } else {
+ return array(
+ "{$association}.{$assocData['foreignKey']}" => $this->identifier("{$Model->alias}.{$Model->primaryKey}")
+ );
+ }
+ case 'belongsTo':
+ if ($assocData['external']) {
+ return array(
+ "{$association}.{$LinkModel->primaryKey}" => '{$__cakeForeignKey__$}'
+ );
+ } else {
+ return array(
+ "{$Model->alias}.{$assocData['foreignKey']}" => $this->identifier("{$association}.{$LinkModel->primaryKey}")
+ );
+ }
+ case 'hasMany':
+ return array("{$association}.{$assocData['foreignKey']}" => array('{$__cakeID__$}'));
+ case 'hasAndBelongsToMany':
return array(
array(
- "{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'
+ "{$association}.{$assocData['foreignKey']}" => '{$__cakeID__$}'
),
array(
- "{$alias}.{$assoc['associationForeignKey']}" => $this->identifier("{$alias2}.{$linkModel->primaryKey}")
+ "{$association}.{$assocData['associationForeignKey']}" => $this->identifier("{$association2}.{$LinkModel->primaryKey}")
)
);
}

0 comments on commit c5c8cb8

Please sign in to comment.
Something went wrong with that request. Please try again.