| 1 |
import { Server, Model, hasMany, belongsTo } from "miragejs"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Mixed | Regressions | 1613 Two bidirectional one-to-many relationships with same target model update ids bug", () => { |
| 4 |
let server; |
| 5 |
|
| 6 |
beforeEach(() => { |
| 7 |
server = new Server({ |
| 8 |
environment: "test", |
| 9 |
models: { |
| 10 |
user: Model.extend({ |
| 11 |
authoredPosts: hasMany("post", { inverse: "author" }), |
| 12 |
editedPosts: hasMany("post", { inverse: "editor" }), |
| 13 |
}), |
| 14 |
post: Model.extend({ |
| 15 |
author: belongsTo("user", { inverse: "authoredPosts" }), |
| 16 |
editor: belongsTo("user", { inverse: "editedPosts" }), |
| 17 |
}), |
| 18 |
}, |
| 19 |
}); |
| 20 |
}); |
| 21 |
|
| 22 |
test(`it works, and all inverses are correctly updated`, () => { |
| 23 |
let user = server.schema.users.create(); |
| 24 |
let post = server.schema.posts.create(); |
| 25 |
|
| 26 |
post.update({ |
| 27 |
authorId: user.id, |
| 28 |
editorId: user.id, |
| 29 |
}); |
| 30 |
|
| 31 |
expect(server.db.posts.find(1)).toEqual({ |
| 32 |
id: "1", |
| 33 |
authorId: "1", |
| 34 |
editorId: "1", |
| 35 |
}); |
| 36 |
expect(server.db.users.find(1)).toEqual({ |
| 37 |
id: "1", |
| 38 |
authoredPostIds: ["1"], |
| 39 |
editedPostIds: ["1"], |
| 40 |
}); |
| 41 |
}); |
| 42 |
}); |