Yii Framework Forum: Yii model relation giving error if defined "On" - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii model relation giving error if defined "On"

#1 User is offline   Baso 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 09-January 17

Posted 23 May 2017 - 03:05 AM

Hi,
I have a model
transportation which has defined relation
'route123'=>array(self::BELONGS_TO, 'routedetails','','on'=>'route123.id=t.route_id', 'joinType'=>'inner JOIN','alias'=>'route123'  ),

in view

$trans=transportation::model()->findbyattaributes(array('id'=>1));
$route=$trans->route123; //will give error 

in sql log the error is
SELECT * FROM `route_details` `route123`  WHERE ((route123.id=t.route_id) AND (route123.is_deleted='0'))

so t.route_id is not being resolved!
but if I set the relation to
'route123'=>array(self::BELONGS_TO, 'routedetails','route_id','joinType'=>'inner JOIN','alias'=>'route123'  )

$route=$trans->route123; will work so how to fix as the first relation with the on defined ?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users