dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Update properties of extended model #714

Open ghost opened 8 years ago

ghost commented 8 years ago

User and Profile are defined as below:

var User = db.qDefine('User', {
    ID: {type: 'serial', key: true},
    Username: {type: 'text', size: 15, required: true},
    Email: {type: 'text', size: 128, required: true}
    ...
  }, {}});

User.extendsTo("profile", {
    CompanyName: {type: 'text', size: 32}
    ...
  }, {field: 'UserID'});

I update company_name of User(ID=1) with following code

User.qGet(1).then(function(user) {
    return Q.nfbind(user.getProfile)().then(function(profile) {
        profile.CompanyName = 'New company';
        return Q.nfbind(user.setProfile)(profile).then(function() {});
      });
  })
});

2016-03-15_231513

I found in sql log, orm executed DELETE and then UPDATE. Could you tell me how to update properties of extendsTo model. Many thanks.