I have a table message( id, subject, sender,receiver,send_time) where receiver stores the profile_id of profile table containing (id,first_name,last_name) and sender stores the user_id who is sending messages and another table mail(id,subject,sender,receiver,send_time) where receiver stores email address having no references.
$criteria1 = new CDbCriteria;
$criteria->with=’messageprofile’;
$criteria->select = ‘ sender, messageprofile.first_name, send_time, subject ‘ ;
$dataProvider=new CActiveDataProvider(‘Messages’, array(‘criteria’ => $criteria,));
$criteria2 = new CDbCriteria;
$criteria->select = ‘ sender, receiver, send_time, subject ‘ ;
$dataProvider2=new CActiveDataProvider(‘Mails’, array(‘criteria’ => $criteria2,));
$dataProvider= new CArrayDataProvider(array_merge($messages, $mails), array(
'sort'=> array(
'attributes'=> array(
'send_time DESC',
),
),
));
In my view page i am using CGridView to view data.I want to show a column of subject,send_time, sender and receiver where receiver includes names in case of message table and email addresses in case of mail table.
Relation is:
array(
‘messageprofile’ => array(self::BELONGS_TO, ‘Profiles’, ‘receiver’),
)
Error:
Active record “Messages” is trying to select an invalid column “messageprofile.first_name” . Note, the column must exist in the table or be an expression with alias.
Please help me.