Merging fixes and enhancements into trunk.

Revision: [2066]
Change the bindTo<ModelName>() 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
This commit is contained in:
phpnut 2006-02-20 05:09:48 +00:00
parent 02d90348f8
commit 35997a1e84
3 changed files with 42 additions and 32 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.8.2065
0.10.8.2067

View file

@ -368,8 +368,7 @@ class Model extends Object
* PHP4 Only
*
* Handles custom method calls, like findBy<field> 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;
}
/**

View file

@ -366,8 +366,7 @@ class Model extends Object
/**
* Handles custom method calls, like findBy<field> 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;
}
/**