GSTAR
(Omzy83)
July 23, 2014, 12:40pm
1
Is it possible to have ONE relation which can match on two foreign keys using an OR condition?
For example I have a table called "messages" with two foreign keys - "from_user_id" and "to_user_id". I want to retrieve all messages "from" and "to" current user.
User model:
'messages'=>array(self::HAS_MANY, 'MessageThread', 'from_user_id, to_user_id'),
This creates an AND condition on the foreign key relation. How can I make it perform OR condition?
negar
(Nar8591)
July 24, 2014, 4:40am
2
GSTAR:
Is it possible to have ONE relation which can match on two foreign keys using an OR condition?
For example I have a table called "messages" with two foreign keys - "from_user_id" and "to_user_id". I want to retrieve all messages "from" and "to" current user.
User model:
'messages'=>array(self::HAS_MANY, 'MessageThread', 'from_user_id, to_user_id'),
This creates an AND condition on the foreign key relation. How can I make it perform OR condition?
hi
Try It Now
'messages'=>array(self::HAS_MANY, 'MessageThread', 'from_user_id')
'messages2'=>array(self::HAS_MANY, 'MessageThread', 'to_user_id')
and
$criteria->condition = 'from_user_id = :temp OR to_user_id = :temp ';
Keith
(Kburton)
July 24, 2014, 11:22am
3
As suggested above, you should probably have two different relations, perhaps called messagesSent and messagesReceived.
GSTAR
(Omzy83)
July 24, 2014, 11:53am
4
No worries. I was hoping it could all be done in one relation.
In the end I’ve just created a new function that does a normal CDbCriteria query to retrieve both sent and received.