Hi,
I’m trying to get a “conversation” activerecord and the last message of this conversation .
I have in Conversation
public function relations()
{
return = array(
'messages' => array(self::HAS_MANY, 'Message', 'conversation_id'),
);
}
and in Message
public function scopes()
{
return array(
'sent'=>array(
'condition'=> $this->getTableAlias().'.status=1',
),
'deleted'=>array(
'condition'=> $this->getTableAlias().'.status=-1',
),
'draft'=>array(
'condition'=> $this->getTableAlias().'.status=0',
),
'last'=>array(
'order'=> $this->getTableAlias().'.created DESC',
'limit'=>1,
),
);
}
So i’m trying to get my conversations and the last message like this :
$collection = Conversation::model()->with(array('messages'=>array('scopes'=>array('last'))))->findAll()
also tried witht the together option
$collection = Conversation::model()->with(array('messages'=>array('scopes'=>array('last'),'together'=>false)))->findAll()
$collection = Conversation::model()->with(array('messages'=>array('scopes'=>array('last'),'together'=>true)))->findAll()
but it’s nor working i have error
Property "Conversation.custom_message" is not defined.
when i do
foreach( $collection as $c ){
echo $c->custom_message;
}
where custom_message is a message table column.
what is wrong ?
Thanks