| 1 |
A belongsTo relationship has the following possible schemas. For each schema, the child model can be in six states with respect to its parent: |
| 2 |
|
| 3 |
- the child can be saved and the parent can be one of: undefined, new or saved |
| 4 |
|
| 5 |
- the child can be new and the parent can be one of: undefined, new or saved |
| 6 |
|
| 7 |
This is how the tests in this directory are organized. |
| 8 |
|
| 9 |
# belongsTo |
| 10 |
|
| 11 |
Given Post, Author models |
| 12 |
For the Post model |
| 13 |
|
| 14 |
## basic |
| 15 |
|
| 16 |
author: belongsTo() |
| 17 |
|
| 18 |
## named |
| 19 |
|
| 20 |
writer: belongsTo('author') |
| 21 |
|
| 22 |
## reflexive, one-way |
| 23 |
|
| 24 |
post: belongsTo() |
| 25 |
|
| 26 |
## named reflexive |
| 27 |
|
| 28 |
childPost: belongsTo('post') |
| 29 |
|
| 30 |
## inverse (implicit) |
| 31 |
|
| 32 |
author: belongsTo() |
| 33 |
|
| 34 |
(author) |
| 35 |
posts: hasMany() |
| 36 |
|
| 37 |
## inverse (explicit) |
| 38 |
|
| 39 |
author: belongsTo('author', { inverse: 'redPosts' }) |
| 40 |
|
| 41 |
(author) |
| 42 |
posts: hasMany('post', { inverse: 'author' }) |
| 43 |
drafts: hasMany('post') |
| 44 |
|
| 45 |
## multiple (conflict) |
| 46 |
|
| 47 |
primaryAuthor: belongsTo('author') |
| 48 |
secondaryAuthor: belongsTo('author') |
| 49 |
|
| 50 |
(author) |
| 51 |
posts: hasMany() |