#Sequelize while adding retrieve all attributes

I would like to find a way to retrieve all my attributes while inserting in my Database.

models.association.build(associationParams)
    .save()
    .then(function(assoAdded){
        return next(assoAdded);
    }).catch(function(err){
        // # TODO : implement error Handler
        return next(err);
    });

I got this :

{
   "idAssoParente": null,
   "id": 420,
   "name": "a",
   "email": "aa@aa.aa",       
   "updated_at": "2015-07-29T17:12:47.000Z",
   "created_at": "2015-07-29T17:12:47.000Z"
}

But I want to return all my fields like description , phone , city from my database even if they are empty. Should I necessarily do a find after adding to get all my fields or does it exist a way to retrieve my fields without doing an other request ? Thanks

Answers


In short, yes you would need to query your db to return the info. I just started using Sequelize but I found the following worked for me.

// if all the info you need is in your user  
Users.build({req.body})
        .save()
            .then(function(newUser){
               Users.find({where: {UserID: newUser.UserID}}).then(function(user){
                 //resolve your promise as you please.
               });

  // or if address info is in another model you can use eager loading.
  Users.build({req.body})
        .save()
            .then(function(newUser){
               Users.find({where: {UserID: newUser.UserID},
                                  include: [{
                                      model: address
                                  }]
                          }).then(function(user){
                 //resolve your promise as you please.
               });

Need Your Help

fail to get json object in javascript from php

javascript php jquery

I am trying to pass json string to javascript from php, so at first i did

Removing done button in media picker

iphone objective-c mpmediapickercontroller

In my app I am using media picker when I click on a button media picker will appear. After selecting the required song I have to press done button to dismiss that picker view.