简体   繁体   中英

Yii - find all by composite key

How do I find all by primary key? I don't want to specify the start and end dates as they aren't relevant when opening within booking form

$bookingRoom = BookingRoom::model()->findByPk(array('roomId' => 1, 'bookingId' => 1, 'startDate' => '20140619', 'endDate' => '20140620'));

You should use the findAllByAttributes() option:

$bookingRoom = BookingRoom::model()->findAllByAttributes(array('roomId' => 1, 'bookingId' => 1, 'startDate' => '20140619', 'endDate' => '20140620'));

If you don't want the startDate and endDate included remove it from the array.

Here is the documentation: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#findAllByAttributes-detail

you can try this:

 $id = // code to set the id
 $bookingRoom = BookingRoom::model()->findAllByPk($id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM