MCPcopy
hub / github.com/sequelize/sequelize / doStuffWithUser

Function doStuffWithUser

types/test/typescriptDocs/ModelInit.ts:195–215  ·  types/test/typescriptDocs/ModelInit.ts::doStuffWithUser
()

Source from the content-addressed store, hash-verified

193User.hasOne(Address, { sourceKey: class="st">"id" });
194
195async function doStuffWithUser() {
196 const newUser = await User.create({
197 name: class="st">"Johnny",
198 preferredName: class="st">"John",
199 });
200 console.log(newUser.id, newUser.name, newUser.preferredName);
201
202 const project = await newUser.createProject({
203 name: class="st">"first!",
204 ownerId: 123,
205 });
206
207 const ourUser = await User.findByPk(1, {
208 include: [User.associations.projects],
209 rejectOnEmpty: true, class="cm">// Specifying true here removes `null` from the return type!
210 });
211
212 class="cm">// Note the `!` null assertion since TS can't know if we included
213 class="cm">// the model or not
214 console.log(ourUser.projects![0].name);
215}

Callers

nothing calls this directly

Calls 3

logMethod · 0.80
findByPkMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected