Hello,
Could anybody please tell me what's wrong with this:
I have a MANY_MANY relation (declared in MySQL with innoDB) but when I try to retrieve data from this relation, Yii returns errors.
Table Event
eventId (PK) - integer(6) unsigned
eventName
Table Artist
artistId (PK) - integer(6) unsigned
artistName
Table Event_Artist
eventId (PK) - integer(6) unsigned references Event.eventId
artistId (PK) - integer(6) unsigned references Artist.artistId
Model Event
public function relations()
{
return array(
'artists'=>array(self::MANY_MANY,'Artist','Event_Artist(eventId,artistId)'),
);
}
Model Artist
public function relations()
{
return array(
'events'=>array(self::MANY_MANY,'Event','Event_Artist(eventId,artistId)'),
);
}
Model Event_Artist
public function relations()
{
return array(
'event'=>array(self::BELONGS_TO,'Event','eventId'),
'artist'=>array(self::BELONGS_TO,'Artist','artistID'),
);
}
If I try to do the following in the EventController:
public function actionAdmin()
{
...
$eventList=Event::model()->with('artists')->findAll();
$this->render('admin',array(
'eventList'=>$eventList,
...
));
}
Yii returns:
Invalid argument supplied for foreach()
Any other relations with Event model are ok. If I use the Event::model()->findAll() and then I try to write in the Event update view:
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'Artists'));
$artists = $event->artists;
$this->endWidget();
?>
I got the error:
Invalid argument supplied for foreach()
I need to retrieve all the artists related to the event and show them in a tab beside the event _form data. It's like:
|Event Data| |Artists in Event|
renders Event_form renders artists who have played in the event
I have related data in Event_Artist, Event and Artist tables…really can't see what's wrong…it seems like the MANY_MANY relation simply doesn't work for me.
Please, I need to solve this to release a project for my client, if somebody could help me I would appreciate so much!
Thanks,