balderdashy / sails

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

Datastore selection for Archive model #7313

Open TimurK opened 10 months ago

TimurK commented 10 months ago

Node version: v18.16.0 Sails version (sails): 1.5.8 ORM hook version (sails-hook-orm): 4.0.2 Organics hook version (sails-hook-organics): 2.2.2 Grunt hook version (sails-hook-grunt): 5.0.0 DB adapter & version (): sails-postgresql@5.0.1 DB adapter & version (): sails-mongo@2.0.1


I have default datastore which is uses sails-postgresql adapter and most of my Models uses this default datastore.

  // config/datastores.js

  default: {
    adapter: require('sails-postgresql'),
    url: 'postgresql://user:pass@postgres:5432/devdefaultdb',
  }
// models/PostgresModel.js

module.exports = {

  attributes: {

    mypostgresattribute: {
      type: 'string',
      required: true,
    },

  },

};

Also i have additional sails-mongo datastore and one model in it. Datastore for this model configured throught datastore: paramether.

  // config/datastores.js

  devMongoDb: {
    adapter: require('sails-mongo'),
    url: 'mongodb://user:pass@mongo:27017/devmongodb',
  },
// models/MongoModel.js

module.exports = {

  datastore: 'devMongoDb',

  attributes: {

    id: {
      type: 'string',
      columnName: '_id'
    },

    mymongoattribute: {
      type: 'string',
      required: true,
    },

  },

};

All working as expected. I can create models on both datastores without any problems using PostgresModel.create() and MongoModel.create().

But when i calling PostgresModel.archive() method on models that uses default datastore Archive collection appears in devMongoDb datastore.

It is posible to store Archive collection on the source datastore?

sailsbot commented 10 months ago

@TimurK 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.