balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.82k stars 1.95k forks source link

ORM and getDatastore(var) / transaction with usingConnection #6813

Open nlgi opened 5 years ago

nlgi commented 5 years ago

Node version: 10.16 Sails version (sails): 1.2.3 ORM hook version (sails-hook-orm): 2.1.1 Sockets hook version (sails-hook-sockets): 2.0.0 DB adapter & version (e.g. sails-postgresql): 1.0.2


Hi,

I tried to use the transaction object: https://sailsjs.com/documentation/reference/waterline-orm/datastores/transaction

My code:

fn: async function (inputs, exits) { 
   await sails.getDatastore('mydb')
      .transaction(async (db)=> {
        const newsalle = await Salle.update({ id_salle: 1 }).set({nom: 'aaa'}).usingConnection(db).fetch();
        sails.log('newsalle',newsalle);
      });
  }

The log i ok, there is no error, but nothing happens in database. I define my datastore here with getDatastore function. In ma datastore.js file, I haven't a default config, and no datastore is setting in my model, because it's dynamic.

I specify: in my model, sails.getDatastore('mydb').sendNativeQuery() is working very well. Just the ORM functions that not working (update, create...).

Thanks for your help,

sailsbot commented 5 years ago

@nlgi Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

johnabrams7 commented 5 years ago

Hi @nlgi, thanks so far for the attention to this issue and example code. I'm still unsure where the configuration issue may reside - do you perhaps have a repo of this code for us to further analyze and test the ORM functions with?