Permalink
Browse files

Make getConstraint() a tiny bit more readable.

  • Loading branch information...
1 parent a2f043d commit 2366e7c7b5ded27800f8dc21ca62220bc61d4261 @bar bar committed Nov 13, 2013
Showing with 26 additions and 11 deletions.
  1. +26 −11 lib/Cake/Model/Datasource/DboSource.php
@@ -1729,22 +1729,37 @@ public function getConstraint($type, $model, $linkModel, $alias, $assoc, $alias2
}
switch (true) {
- case ($assoc['external'] && $type === 'hasOne'):
- return array("{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}');
- case ($assoc['external'] && $type === 'belongsTo'):
- return array("{$alias}.{$linkModel->primaryKey}" => '{$__cakeForeignKey__$}');
- case (!$assoc['external'] && $type === 'hasOne'):
- return array("{$alias}.{$assoc['foreignKey']}" => $this->identifier("{$model->alias}.{$model->primaryKey}"));
- case (!$assoc['external'] && $type === 'belongsTo'):
- return array("{$model->alias}.{$assoc['foreignKey']}" => $this->identifier("{$alias}.{$linkModel->primaryKey}"));
+ 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__$}'));
+ return array(
+ "{$alias}.{$assoc['foreignKey']}" => array('{$__cakeID__$}')
+ );
case ($type === 'hasAndBelongsToMany'):
return array(
- array("{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'),
- array("{$alias}.{$assoc['associationForeignKey']}" => $this->identifier("{$alias2}.{$linkModel->primaryKey}"))
+ array(
+ "{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'
+ ),
+ array(
+ "{$alias}.{$assoc['associationForeignKey']}" => $this->identifier("{$alias2}.{$linkModel->primaryKey}")
+ )
);
}
+
return array();
}

0 comments on commit 2366e7c

Please sign in to comment.