Skip to content

Commit

Permalink
The 'condition' declared in the scopes of the related AR classes will…
Browse files Browse the repository at this point in the history
… now be put in the 'WHERE' clause when performing relational AR queries
  • Loading branch information
alexander.makarow committed Feb 23, 2011
1 parent 8ffea45 commit 44b310c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -35,6 +35,7 @@ Version 1.1.7 to be released
- Chg #2001: CGridView now renders footer after the body content (Qiang)
- Chg: Upgraded jQuery to version 1.5 (Sam Dark)
- Chg: Upgraded jQuery UI to version 1.8.9 (Sam Dark)
- Chg: The 'condition' declared in the scopes of the related AR classes will now be put in the 'WHERE' clause when performing relational AR queries (creocoder, Sam Dark)
- New: Added support for query caching (Qiang)

Version 1.1.6 January 16, 2011
Expand Down
4 changes: 3 additions & 1 deletion UPGRADE
Expand Up @@ -21,7 +21,9 @@ General upgrade intructions

Upgrading from v1.1.6
---------------------

- The 'condition' declared in the scopes of the related AR classes will now
be put in the 'WHERE' clause when performing relational AR queries. If you
need to to put it into 'ON' clause of the JOIN statement use 'on'.

Upgrading from v1.1.5
---------------------
Expand Down
2 changes: 1 addition & 1 deletion framework/db/ar/CActiveFinder.php
Expand Up @@ -225,7 +225,7 @@ private function buildJoinTree($parent,$with,$options=null)
if(!empty($options['scopes']))
$criteria->scopes=$options['scopes'];
$model->applyScopes($criteria);
$relation->mergeWith($criteria,true);
$relation->mergeWith($criteria);

// dynamic options
if($options!==null)
Expand Down
28 changes: 6 additions & 22 deletions framework/db/ar/CActiveRecord.php
Expand Up @@ -1909,10 +1909,9 @@ public function __construct($name,$className,$foreignKey,$options=array())
/**
* Merges this relation with a criteria specified dynamically.
* @param array $criteria the dynamically specified criteria
* @param boolean $fromScope whether the criteria to be merged is from scopes
* @since 1.0.5
*/
public function mergeWith($criteria,$fromScope=false)
public function mergeWith($criteria)
{
if($criteria instanceof CDbCriteria)
$criteria=$criteria->toArray();
Expand Down Expand Up @@ -1997,14 +1996,13 @@ class CStatRelation extends CBaseActiveRelation
/**
* Merges this relation with a criteria specified dynamically.
* @param array $criteria the dynamically specified criteria
* @param boolean $fromScope whether the criteria to be merged is from scopes
* @since 1.0.5
*/
public function mergeWith($criteria,$fromScope=false)
public function mergeWith($criteria)
{
if($criteria instanceof CDbCriteria)
$criteria=$criteria->toArray();
parent::mergeWith($criteria,$fromScope);
parent::mergeWith($criteria);

if(isset($criteria['defaultValue']))
$this->defaultValue=$criteria['defaultValue'];
Expand Down Expand Up @@ -2055,25 +2053,12 @@ class CActiveRelation extends CBaseActiveRelation
/**
* Merges this relation with a criteria specified dynamically.
* @param array $criteria the dynamically specified criteria
* @param boolean $fromScope whether the criteria to be merged is from scopes
* @since 1.0.5
*/
public function mergeWith($criteria,$fromScope=false)
public function mergeWith($criteria)
{
if($criteria instanceof CDbCriteria)
$criteria=$criteria->toArray();
if($fromScope)
{
if(isset($criteria['condition']) && $this->on!==$criteria['condition'])
{
if($this->on==='')
$this->on=$criteria['condition'];
else if($criteria['condition']!=='')
$this->on="({$this->on}) AND ({$criteria['condition']})";
}
unset($criteria['condition']);
}

parent::mergeWith($criteria);

if(isset($criteria['joinType']))
Expand Down Expand Up @@ -2150,14 +2135,13 @@ class CHasManyRelation extends CActiveRelation
/**
* Merges this relation with a criteria specified dynamically.
* @param array $criteria the dynamically specified criteria
* @param boolean $fromScope whether the criteria to be merged is from scopes
* @since 1.0.5
*/
public function mergeWith($criteria,$fromScope=false)
public function mergeWith($criteria)
{
if($criteria instanceof CDbCriteria)
$criteria=$criteria->toArray();
parent::mergeWith($criteria,$fromScope);
parent::mergeWith($criteria);
if(isset($criteria['limit']) && $criteria['limit']>0)
$this->limit=$criteria['limit'];

Expand Down

0 comments on commit 44b310c

Please sign in to comment.