Yii Framework Forum: Infamous updateAll problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Infamous updateAll problem Rate Topic: -----

#1 User is offline   zarun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 13-January 12

Posted 13 January 2012 - 01:10 PM

Hi,

I've been trying to figure out what went wrong in this:

$bc_model->updateAll(array('business_id' => $business_id),'contact_id IN (:contactids)',array(':contactids' => implode(',',$contactids)));


The query generated is:
system.db.CDbCommand.execute(UPDATE `business_contact` SET `business_id`=:yp0 WHERE contact_id IN (:contactids))


What is it that I am missing? :(
0

#2 User is offline   loryck 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 31-March 09

Posted 16 January 2012 - 11:17 AM

what is the error ?
0

#3 User is offline   Say_Ten 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 17-September 10

Posted 16 January 2012 - 12:26 PM

I suspect that you end up with contact ids being one big string with commas in. Perhaps build a CDbCriteria using the addInCondition and parsing that in for the criteria would be best for you.
0

#4 User is offline   zarun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 13-January 12

Posted 24 January 2012 - 11:01 AM

View PostSay_Ten, on 16 January 2012 - 12:26 PM, said:

I suspect that you end up with contact ids being one big string with commas in. Perhaps build a CDbCriteria using the addInCondition and parsing that in for the criteria would be best for you.


Thanks a lot,
I tried this and it worked:
$criteria->addInCondition( "contact_id" , $contactids ); 
$model->updateAll(array('business_id' => $business_id), $criteria);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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