Hi !
I would like to check if a User is related to a specific event.
I have :
Event (id, name, description…) User_event(user_id, event_id, is_in,…)
In Event.php (model) :
public function relations()
{
$r = array
'userCheck' => array(self::HAS_ONE,
'UserEvent',
'event_id', ),
'userEvent' => array(self::HAS_MANY,
'UserEvent',
'event_id',),
}
I also have this method :
/**
* A scope that make sure the user is associated to the event
*
* @return Event
*/
public function userEvent($userID)
{
$criteria = new CDbCriteria();
$criteria->with = array('userCheck');
$criteria->condition = 'userCheck.user_id = :event_user_id ';
$criteria->params = array(':event_user_id'=>$userID);
$this->getDbCriteria()->mergeWith($criteria);
return $this;
}
But, because of this, when I update an event, userCheck is checked and find that there’s not a single user_event attached to a specific Event. Logical because there could be several user for an event. So, it deletes ALL other user_event attached to this event…
How to make sure that userCheck checks only if a spectific user is attached to the event ?
I precise that the code above is not mine but other developer’s one.
–> User exists in THIS event…
How can I do that ?
Thanks