Revision #4 has been created by Maurizio Domba Cerin on Apr 26, 2011, 8:30:42 AM with the memo:
« previous (#3) next (#6) »
Relations: BELONGS_TO versus HAS_ONE
relations, HAS_ONE, BELONGS_TO
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.
Both `BELONGS_TO` and `HAS_ONE` are about linking two models together, and sound like the same thing, but they link in essentially opposite directions. Let's illustrate with three simple tables, each of which has a primary key
`id`, and a number of linking fields (`user_id`) that reference the User table.