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

Function doStuffWithUser

types/test/typescriptDocs/ModelInit.ts:195–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…