public function relations() {
return array(
myRelation=>array(self::HAS_ONE, 'OtherModel', 'myModel_id',
'on'=>'myRelation.someField=whatever' // HOW DO I NAME myRelation table alias in a generic way?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />
)
)
}
Normally, in order to mention the OtherModel table in the on condition, I would use "myRelation" as the table alias, as that is the default alias.
However, if this relation is used with another on-the-fly custom alias, that won’t work anymore:
If there’s no way to do this, then it’s definitely a feature that is missing.
Having to do that every time you use the relation would be terrible.
I don’t think that would work. $this->tableAlias() would be evaluated when the “scopes()” method is called. I don’t think that’s when the scope is applied. Or is it?
Anyway, you can define the scope as a method; that is the workaround I currently use, but it’s awful, I was hoping there was a better solution I still have to explicitly include the scope every time I use the relation