HAS_MANY relation with composite failed in validation


I got stuck with a Yii bug…

I have an HAS_MANY relation with composite key defined like that :

 'precalculated' => array(self::HAS_MANY, 'PrecalculatedUserMoovpoint', array('checkin_id' => 'checkin_id'))

But when I do something like that (findAll, foreach, update) :

$usersEvent = UserEvent::model()->event($eventID)->getmoovpoint(true)->pointsToWin()->findAll();

            if ($_POST['action'] == 'validate') {

                foreach ($usersEvent as $ue) {

                    if($ue->partner_validation === null) {

                        $ue->partner_validation = UserEvent::PARTNER_VALIDATED;

                        $ue->save() ;




I got this error :

Illegal offset type (/var/www/vhost/library/App/extensions/awegen/components/EActiveRecordRelationBehavior.php:205)</p>

That corresponds, in EActiveRecordRelationBehavior.php, to :

// @todo add support for composite primary keys


The @todo reflects the issue that I encountered…

$relation[2] is equal to an array that’s why it crashes.

The strange thing is when I do something like that this error does not appear :

 $ue = UserEvent::model()->user($id)->event($eventID)->find();

                    $ue->partner_validation = UserEvent::PARTNER_VALIDATED;




uses the specific relation "precalculated"

Someone can explain that ? Even correct it ?

Thanks !

Ok I solved my problem by replacing the relation’s definition :

 'precalculated' => array(self::HAS_MANY, 'PrecalculatedUserMoovpoint', array('checkin_id' => 'checkin_id')

By :

'precalculated' => array(self::HAS_MANY, 'PrecalculatedUserMoovpoint', array('id' => 'checkin_id'), 'through' => 'checkin')

Where checkin is also a relation :

'checkin' => array(self::BELONGS_TO, 'Checkin', 'checkin_id'),

Strange that first definition works well for retrieving data but not for updating/saving…