When one needs to select a record in a table that do not have related records through a relation, it is generally suggested to use a subquery.
Personnaly, I prefer a high level approach, and I have a method to do it with scopes.
Updated 3 years ago by fsb – Tips – 5 comments – viewed 39,707 times
( +16 / -1 )
There are situations in which Active Record will generate nonsense queries from what a nieve Yii user might think is reasonable code. One such situation is a CActiveDataProvider using CDbCriteria to get data from parent and 1:n child table with a condition on the child table.
Updated 4 years ago by Jorgee – FAQs – 9 comments – viewed 128,890 times
( +69 / -1 )
It's very common to see new Yii users confusing the relations HAS_ONE and BELONGS_TO, and getting it wrong means you won't get proper values back. And though we'll talk about HAS_MANY as well, we're specifically omitting the MANY_MANY relation because it's a whole different animal.
I keep a reference to some simple but painful task if you forget a common or something. I am new to Yii and this took awhile for me to figure out. Everything I read said do this or do that and not a single one worked for me. However, the following did.