Fairly simple problem, just cant find the good/clean way to do this without making a call to another find
I've got my node app rigged up with Angular-Resource, and I'm just making some round-trip like data calls on new or changed data.
So ngResource making the $save()
call to my /api/users/:id
and such. And Node reacts to this call by creating or finding the user, making the updates, and saving them.
Whether through create()
or save()
, it returns the created record, and for right now, I use res.json(user)
to spill the created/returned record for my Angular to handle populating my view with the updated information
Now, I know with Sequelizes find()
and findAll()
methods, I can use findAll({ include: [{ all: true }]})
or specify my models individually.
What I want to know is, what is the best way to get my records associations on save/create
and unfortunately, this just doesn't work:
models.User.create(newuser, {include:[{ all: true }]}).then(function(user) {
res.json(user);
});
Do I really have to perform another find()
just to get my managed models associations?
To better illustrate the opted solution from RedactedProfile's comment, here's the code.
models.User
.create(newuser, {include:[{ all: true }]})
.then(user => {
user.reload().then(user => { res.json(user); })
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With