From 35997a1e840657444a0a4c7bb34919805eca9c85 Mon Sep 17 00:00:00 2001 From: phpnut Date: Mon, 20 Feb 2006 05:09:48 +0000 Subject: [PATCH] Merging fixes and enhancements into trunk. Revision: [2066] Change the bindTo() to bindModel() This works similar to before but has sytax as follows. $this->Book->bindModel(array('belongsTo' => array('Author' => array('conditions' => 'these conditions', 'order' => 'this order by DESC', 'foreignKey' => 'foreign key',)))); git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2067 3807eeeb-6ff5-0310-8944-8be069107fe0 --- VERSION.txt | 2 +- cake/libs/model/model_php4.php | 37 +++++++++++++++++++--------------- cake/libs/model/model_php5.php | 35 ++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 827e9fdf6..e05ea3b8e 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.8.2065 \ No newline at end of file +0.10.8.2067 \ No newline at end of file diff --git a/cake/libs/model/model_php4.php b/cake/libs/model/model_php4.php index 0364070b6..12aad85df 100644 --- a/cake/libs/model/model_php4.php +++ b/cake/libs/model/model_php4.php @@ -368,8 +368,7 @@ class Model extends Object * PHP4 Only * * Handles custom method calls, like findBy for DB models, - * custom RPC calls for remote data sources and bind to model calls - * to change associations on the fly. + * and custom RPC calls for remote data sources * * @param unknown_type $method * @param unknown_type $params @@ -379,22 +378,28 @@ class Model extends Object */ function __call($method, $params, &$return) { - $args = func_get_args(); - if (count($args) > 1 && strpos(low($args[0]), 'bindto') === 0) + $return = $this->db->query($method, $params, $this); + return true; + } + +/** + * Bind model associations on the fly. + * + * @param array $params + * @return true + */ + function bindModel($params) + { + foreach($params as $assoc => $model) { - $assoc = Inflector::camelize(preg_replace('/bindto/i', '', $args[0])); - $this->__constructLinkedModel($assoc, $assoc); - $type = array_keys($args[1][0]); - $this->__backAssociation[$type[0]] = $this->{$type[0]}; - $this->{$type[0]}[$assoc] = $args[1][0][$type[0]]; - $this->__generateAssociation($type[0], $assoc); - return true; - } - else - { - $return = $this->db->query($method, $params, $this); - return true; + $modelName = array_keys($model); + $this->__constructLinkedModel($modelName[0], $modelName[0]); + $type = $assoc; + $this->__backAssociation[$type] = $this->{$type}; + $this->{$type}[$modelName[0]] = $model[$modelName[0]]; + $this->__generateAssociation($type, $modelName[0]); } + return true; } /** diff --git a/cake/libs/model/model_php5.php b/cake/libs/model/model_php5.php index ac5130faa..bd109eab9 100644 --- a/cake/libs/model/model_php5.php +++ b/cake/libs/model/model_php5.php @@ -366,8 +366,7 @@ class Model extends Object /** * Handles custom method calls, like findBy for DB models, - * custom RPC calls for remote data sources and bind to model calls - * to change associations on the fly. + * and custom RPC calls for remote data sources * * @param unknown_type $method * @param array $params @@ -376,21 +375,27 @@ class Model extends Object */ function __call($method, $params) { - $args = func_get_args(); - if (count($args) > 1 && strpos(low($args[0]), 'bindto') === 0) + return $this->db->query($method, $params, $this); + } + +/** + * Bind model associations on the fly. + * + * @param array $params + * @return true + */ + function bindModel($params) + { + foreach($params as $assoc => $model) { - $assoc = preg_replace('/bindto/i', '', $args[0]); - $this->__constructLinkedModel($assoc, $assoc); - $type = array_keys($args[1][0]); - $this->__backAssociation[$type[0]] = $this->{$type[0]}; - $this->{$type[0]}[$assoc] = $args[1][0][$type[0]]; - $this->__generateAssociation($type[0], $assoc); - return true; - } - else - { - return $this->db->query($method, $params, $this); + $modelName = array_keys($model); + $this->__constructLinkedModel($modelName[0], $modelName[0]); + $type = $assoc; + $this->__backAssociation[$type] = $this->{$type}; + $this->{$type}[$modelName[0]] = $model[$modelName[0]]; + $this->__generateAssociation($type, $modelName[0]); } + return true; } /**