Last active
November 25, 2019 09:24
-
-
Save ohcibi/95e66307e7a0ce80fa9d34a5e4be01f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
models: { | |
a: Model.extend({ | |
bs: hasMany() | |
}), | |
b: Model.extend({ | |
cs: hasMany() | |
}), | |
c: Model | |
}, | |
seeds(server) { | |
const cs1 = server.createList('c', 100); | |
const bs1 = server.createList('b', 10); | |
bs1.forEach((b, i) => b.cs = cs1.slice(10*i, 10*i + 10)); | |
console.log(server.schema.bs.all().models.map(b => b.cs.length)); | |
// ==> [0, 0, 0, 0, .....] | |
server.create('a', { bs: bs1.slice(1) }); | |
console.log(server.schema.bs.all().models.map(b => b.cs.length)); | |
// ==> [0, 10, 10, 10, .... | |
server.create('a', { bs: bs1 }); | |
console.log(server.schema.bs.all().models.map(b => b.cs.length)); | |
// ==> [10, 10, 10, 10, .... | |
const cs2 = server.createList('c', 100); | |
const bs2 = server.createList('b', 10); | |
bs2.forEach((b, i) => b.update({ cs: cs2.slice(10*i, 10*i + 10)})); | |
console.log(server.schema.bs.all().models.map(b => b.cs.length)); | |
// ==> [10, 10, 10, 10, .....] | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment