Mike, on 14 January 2010 - 03:05 AM, said:
Ok, what is the name of the relation to authors in your comments record? If it is
authors then try this:
with(array(
'comments.authors'=>array( 'condition' => "authors.name='Mike'"),
))
At least that's what i'd excpect. Couldn't really try out 1.1 ARs yet, but that's what's stated in the changes/upgrade guide.
And btw.: You shouldn't need the 'comments' entry in your with() array. 'comments.authors' will load comments implicitly.
Mike, really the problem with ambiguous names is more complex that my sample, because aliases are not autogenerated now I should care out about different names of my relations in my models, e.g. (based on old sample) if I have relation with name 'authors' in 'Blog' model (the same relation name as in 'Comment' model), thus the code below (example 1) will fire SQL error again.
// 1.
...
with(
'authors',
'comments.authors' => array(
"condition" => "authors.name='Mike'"
)
) // here is an SQL error
...
// 2.
...
with(
'authors',
'comments.authors' => array(
'condition' => "another_authors.name='Mike'",
'alias' => 'another_authors'
)
) // here is a right but hard "new" way
...
// 3.
...
with(
'authors',
'comments.authors' => array(
'condition' => "??.name='Mike'",
)
) // here is a simple "old" way that already not supported
...
I don't know why Yii developers not support '??' aliases anymore, because in my opinion it was quite useful. All aliases were autogenerated and '??' were automatically replaced with them - very good solution and very flexible way.