MCPcopy Index your code
hub / github.com/sequelize/sequelize / doStuffWithUser

Function doStuffWithUser

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

Source from the content-addressed store, hash-verified

198User.hasOne(Address, { sourceKey: 'id' });
199
200async 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();

Callers 1

ModelInit.tsFile · 0.85

Calls 3

logMethod · 0.80
findByPkMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected