Yii Framework Forum: Special relation - Yii Framework Forum

Jump to content

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

Special relation Rate Topic: -----

#1 User is offline   Thomas Jensen 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 01-August 09

Posted 14 January 2010 - 01:42 PM

I would like to have a relation like:
ON (CONCAT('sometext_',`t`.`id`) == `rel`.`itemId`)
Nothing more.
Can i do this in the AR?

Thanks :-)
0

#2 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 15 January 2010 - 07:40 AM

View PostThomas Jensen, on 14 January 2010 - 01:42 PM, said:

I would like to have a relation like:
ON (CONCAT('sometext_',`t`.`id`) == `rel`.`itemId`)
Nothing more.
Can i do this in the AR?

Thanks :-)


try with "on clause"

see this http://www.yiiframew...on-foreign-key/
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#3 User is offline   Thomas Jensen 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 01-August 09

Posted 17 January 2010 - 03:12 PM

Doesn't work, as it always requires me to choose a column for the relation.
0

#4 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 18 January 2010 - 10:48 AM

View PostThomas Jensen, on 17 January 2010 - 03:12 PM, said:

Doesn't work, as it always requires me to choose a column for the relation.


You can put your relations function code here?

you have to put ' ' where is the column name
and use clause 'with' in the find method (not lazy loading)

in the model

'mySpecialRelation'=>array(self::BELONGS_TO,'TableRel','','on'=>'CONCAT(\'sometext_\',`t`.`id`) = `rel`.`itemId`','alias'=>'rel'),


in the controller

  $models=ModelName::model()->with('mySpecialRelation')->findAll();


[edit]

it's work on 1.0.x

This post has been edited by Horacio Segura: 18 January 2010 - 10:50 AM

KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
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