Difference between #3 and #4 of
Relations: BELONGS_TO versus HAS_ONE

Revision #4 has been created by Maurizio Domba Cerin on Apr 26, 2011, 8:30:42 AM with the memo:

removed "of"
« previous (#3) next (#6) »

Changes

Title unchanged

Relations: BELONGS_TO versus HAS_ONE

Category unchanged

FAQs

Yii version unchanged

Tags unchanged

relations, HAS_ONE, BELONGS_TO

Content changed

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 of (`id`), and a number of linking fields (`user_id`) that reference the User table.
~~~
USER table
- id
- name
[...]
56 0
35 followers
Viewed: 164 769 times
Version: 1.1
Category: FAQs
Written by: Steve Friedl
Last updated by: Jorgee
Created on: Apr 26, 2011
Last updated: 11 years ago
Update Article

Revisions

View all history