| 160 | } |
| 161 | |
| 162 | async function populateDatabase(em: MikroORM['em']) { |
| 163 | const authors = [ |
| 164 | new Author({ id: 1, name: 'a', age: 31, email: 'a@a.com' }), |
| 165 | new Author({ id: 2, name: 'b', age: 47, email: 'b@b.com' }), |
| 166 | new Author({ id: 3, name: 'c', age: 26, email: 'c@c.com' }), |
| 167 | new Author({ id: 4, name: 'd', age: 87, email: 'd@d.com' }), |
| 168 | new Author({ id: 5, name: 'e', age: 39, email: 'e@e.com' }), |
| 169 | ]; |
| 170 | authors[0].friends.add([authors[1], authors[3], authors[4]]); |
| 171 | authors[1].friends.add([authors[0]]); |
| 172 | authors[2].friends.add([authors[3]]); |
| 173 | authors[3].friends.add([authors[0], authors[2]]); |
| 174 | authors[4].friends.add([authors[0]]); |
| 175 | authors[0].buddies.add([authors[1], authors[3], authors[4]]); |
| 176 | authors[1].buddies.add([authors[0]]); |
| 177 | authors[2].buddies.add([authors[3]]); |
| 178 | authors[3].buddies.add([authors[0], authors[2]]); |
| 179 | authors[4].buddies.add([authors[0]]); |
| 180 | em.persist(authors); |
| 181 | |
| 182 | const chats = [ |
| 183 | new Chat({ owner: authors[0], recipient: authors[1] }), |
| 184 | new Chat({ owner: authors[0], recipient: authors[2] }), |
| 185 | new Chat({ owner: authors[0], recipient: authors[4] }), |
| 186 | new Chat({ owner: authors[2], recipient: authors[0] }), |
| 187 | ]; |
| 188 | chats[0].messages.add([new Message({ content: 'A1' }), new Message({ content: 'A2' })]); |
| 189 | chats[1].messages.add([new Message({ content: 'B1' }), new Message({ content: 'B2' })]); |
| 190 | chats[3].messages.add([new Message({ content: 'C1' })]); |
| 191 | em.persist(chats); |
| 192 | |
| 193 | const publishers = [new Publisher({ id: 1, name: 'AAA' }), new Publisher({ id: 2, name: 'BBB' })]; |
| 194 | em.persist(publishers); |
| 195 | |
| 196 | const books = [ |
| 197 | new Book({ id: 1, title: 'One', author: authors[0] }), |
| 198 | new Book({ id: 2, title: 'Two', author: authors[0] }), |
| 199 | new Book({ id: 3, title: 'Three', author: authors[1] }), |
| 200 | new Book({ id: 4, title: 'Four', author: authors[2] }), |
| 201 | new Book({ id: 5, title: 'Five', author: authors[2] }), |
| 202 | new Book({ id: 6, title: 'Six', author: authors[2] }), |
| 203 | ]; |
| 204 | books[0].publisher = ref(publishers[0]); |
| 205 | books[1].publisher = ref(publishers[1]); |
| 206 | books[2].publisher = ref(publishers[1]); |
| 207 | books[3].publisher = ref(publishers[1]); |
| 208 | books[4].publisher = ref(publishers[1]); |
| 209 | books[5].publisher = ref(publishers[1]); |
| 210 | em.persist(books); |
| 211 | |
| 212 | await em.flush(); |
| 213 | em.clear(); |
| 214 | } |
| 215 | |
| 216 | function getReferences(em: MikroORM['em']): Ref<any>[] { |
| 217 | const forkedEm = em.fork(); |