Yii Framework Forum: AR->findAll bug when condition contains 'with' - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

AR->findAll bug when condition contains 'with' Rate Topic: -----

#1 User is offline   touya 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 07-December 09

Posted 12 January 2010 - 09:21 AM

//Yii1.1 Stable,CActiveRecord line 1185:
	public function findAll($condition='',$params=array())
	{
		if($condition instanceof CDbCriteria && !empty($condition->with) || is_array($condition) && isset($condition['with']))
			return $this->with($condition->with)->findAll($condition);
		Yii::trace(get_class($this).'.findAll()','system.db.ar.CActiveRecord');
		$criteria=$this->getCommandBuilder()->createCriteria($condition,$params);
		return $this->query($criteria,true);
	}

if we define option 'with' in a condition like :
$models=Member::model()->findAll(array(
            'with'=>array('sales'),
            'limit'=>10,
            'offset'=>1,
        ));

//then this line in AR will be executed:
return $this->with($condition->with)->findAll($condition);
//                 ~~~~~~~~~~~~~~~~It's null because we should use $condition['with']

This bug will disable eager loading when we define with option directly in condition.
the trace log is :
2010/01/12 22:24:54 [trace] [system.db.ar.CActiveRecord] Member.findAll() eagerly

2010/01/12 22:24:54 [trace] [system.db.CDbCommand] Querying SQL: SELECT `t`.`mid` AS `t0_c0`, `t`.`name` AS `t0_c1`, `t`.`password` AS `t0_c2`, `t`.`data` AS `t0_c3`, `t`.`expire_time` AS `t0_c4`, `t`.`del_flag` AS `t0_c5`, `t`.`email` AS `t0_c6`, `t`.`sales_id` AS `t0_c7`, `t`.`remark` AS `t0_c8`, `t`.`last_login_time` AS `t0_c9`, `t`.`login_times` AS `t0_c10`, `t`.`created` AS `t0_c11`, `t`.`modified` AS `t0_c12` FROM `member` `t` LIMIT 10 OFFSET 1
2010/01/12 22:24:54 [trace] [system.db.ar.CActiveRecord] lazy loading Member.sales

2010/01/12 22:24:54 [trace] [system.db.CDbCommand] Querying SQL: SELECT `sales`.`mid` AS `t1_c0`, `sales`.`name` AS `t1_c1`, `sales`.`password` AS `t1_c2`, `sales`.`data` AS `t1_c3`, `sales`.`expire_time` AS `t1_c4`, `sales`.`del_flag` AS `t1_c5`, `sales`.`email` AS `t1_c6`, `sales`.`sales_id` AS `t1_c7`, `sales`.`remark` AS `t1_c8`, `sales`.`last_login_time` AS `t1_c9`, `sales`.`login_times` AS `t1_c10`, `sales`.`created` AS `t1_c11`, `sales`.`modified` AS `t1_c12` FROM `member` `sales` WHERE (`sales`.`mid`=:ypl0)
.....
老婆是天使
0

#2 User is offline   touya 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 07-December 09

Posted 12 January 2010 - 09:24 AM

Yii1.1稳定版怎么会有这样的bug??
老婆是天使
0

#3 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 12 January 2010 - 09:40 AM

Thank you. I have fixed this bug in SVN.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users