Hello all!
I've been playing around with Yii for quite a while now, trying to create an administration system for a summer camp which will handle events, participants and money exchanges ( i.e. purchases ). However, now I have met a wall I cannot seem to pass.
I have the following setup between the models Event, Person and Exchange:
Event MANY_MANY Person HAS_MANY Exchange
When I now try to do ( with $model being an Event ):
foreach ( $model -> participants as $participant ) foreach ( $participant -> exchanges as $exchange ) echo $exchange -> amount;
in which participants and exchanges are both lazy loaded, no amounts are printed, even though I know that there are many people connected to the event, and that there are exchanges connected to at least one of the people.
My relations are defined as such:
Person: 'participated_in' => array(self::MANY_MANY, 'Event', 'Participants(event_id, person_id)'), 'exchanges' => array(self::HAS_MANY, 'Exchange', 'person_id') Exchange: 'event' => array(self::BELONGS_TO, 'Event', 'event_id'), 'person' => array(self::BELONGS_TO, 'Person', 'person_id') Event: 'participants' => array(self::MANY_MANY, 'Person', 'Participants(person_id, event_id)'), 'exchanges' => array(self::HAS_MANY, 'Exchange', 'event_id')
The weird part is that if I do:
Person::model()->findByPK(1)->exchanges
I get an empty array. However, if I do:
Exchange::model()->findAllByAttributes(array('person_id' => 1))
I get all the relevant exchanges… :S
Also, I've checked the Yii debug log, and executed the SQL it uses when lazy loading myself, and when running it manually, I get the correct rows in return. Seems like Yii just doesn't manage to parse them correctly?
Hope someone has some better insight on this than I have…
Jon(hoo)