You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -24,15 +24,15 @@ The `belongsTo` helper adds several new properties and methods to your models.
24
24
In this case, our `blog-post` model would now have an `authorId` property, as well as some methods for working with the associated `author` model:
25
25
26
26
```js
27
-
blogPost.authorId; // 1
28
-
blogPost.authorId=2; // updates the relationship
29
-
blogPost.author; // Author instance
27
+
blogPost.authorId; // 1
28
+
blogPost.authorId=2; // updates the relationship
29
+
blogPost.author; // Author instance
30
30
blogPost.author= anotherAuthor;
31
-
blogPost.newAuthor(attrs); // new unsaved author
32
-
blogPost.createAuthor(attrs); // new saved author (updates blogPost.authorId in memory only)
31
+
blogPost.newAuthor(attrs); // new unsaved author
32
+
blogPost.createAuthor(attrs); // new saved author (updates blogPost.authorId in memory only)
33
33
```
34
34
35
-
Note that when a child calls `child.createParent`, the new parent is immediately saved to the `db`, but the child's foreign key is updated *on this instance only*, and is not immediately persisted to the database.
35
+
Note that when a child calls `child.createParent`, the new parent is immediately saved to the `db`, but the child's foreign key is updated _on this instance only_, and is not immediately persisted to the database.
36
36
37
37
In other words, `blogPost.createAuthor` will create a new `author` record, insert it into the `db`, and update the `blogPost.authorId` in memory, but if you were to fetch the `blogPost` from the `db` again, the relationship would not be persisted.
38
38
@@ -44,7 +44,7 @@ To define a to-many relationship, use the `hasMany` helper:
44
44
45
45
```js
46
46
// mirage/models/blog-post.js
47
-
import { Model, hasMany } from'ember-cli-mirage';
47
+
import { Model, hasMany } from"ember-cli-mirage";
48
48
49
49
exportdefaultModel.extend({
50
50
comments:hasMany()
@@ -54,12 +54,12 @@ export default Model.extend({
54
54
This helper adds a `commentIds` property to the `blogPost` model, as well as some methods for working with the associated `comments` collection:
55
55
56
56
```js
57
-
blogPost.commentIds; // [1, 2, 3]
58
-
blogPost.commentIds= [2, 3]; // updates the relationship
59
-
blogPost.comments; // array of related comments
57
+
blogPost.commentIds; // [1, 2, 3]
58
+
blogPost.commentIds= [2, 3]; // updates the relationship
59
+
blogPost.comments; // array of related comments
60
60
blogPost.comments= [comment1, comment2]; // updates the relationship
61
-
blogPost.newComment(attrs); // new unsaved comment
62
-
blogPost.createComment(attrs); // new saved comment (comment.blogPostId is set)
61
+
blogPost.newComment(attrs); // new unsaved comment
62
+
blogPost.createComment(attrs); // new saved comment (comment.blogPostId is set)
Be sure to check out the {{docs-link 'Schema' 'docs.api.item' 'modules/lib/orm/schema~Schema'}}, {{docs-link 'Model' 'docs.api.item' 'modules/lib/orm/model~Model'}} and {{docs-link 'Collection' 'docs.api.item' 'modules/lib/orm/collection~Collection'}} API docs to learn about all the available ORM methods.
209
+
Be sure to check out the {{docs-link 'Schema' 'docs.api.item' 'modules/orm/schema~Schema'}}, {{docs-link 'Model' 'docs.api.item' 'modules/orm/model~Model'}} and {{docs-link 'Collection' 'docs.api.item' 'modules/orm/collection~Collection'}} API docs to learn about all the available ORM methods.
213
210
214
211
We'll also cover Serializers in these guides, where you'll learn how to customize the serialized forms of your models and collections to match your production API.
0 commit comments