()
| 198 | User.hasOne(Address, { sourceKey: 'id' }); |
| 199 | |
| 200 | async function doStuffWithUser() { |
| 201 | const newUser = await User.create({ |
| 202 | name: 'Johnny', |
| 203 | preferredName: 'John', |
| 204 | }); |
| 205 | console.log(newUser.id, newUser.name, newUser.preferredName); |
| 206 | |
| 207 | const project = await newUser.createProject({ |
| 208 | name: 'first!' |
| 209 | }); |
| 210 | |
| 211 | const ourUser = await User.findByPk(1, { |
| 212 | include: [User.associations.projects], |
| 213 | rejectOnEmpty: true // Specifying true here removes `null` from the return type! |
| 214 | }); |
| 215 | |
| 216 | // Note the `!` null assertion since TS can't know if we included |
| 217 | // the model or not |
| 218 | console.log(ourUser.projects![0].name); |
| 219 | } |
| 220 | |
| 221 | (async () => { |
| 222 | await sequelize.sync(); |
no test coverage detected