Sails workaround for deep populate

后端 未结 1 1265
礼貌的吻别
礼貌的吻别 2021-01-06 06:48

I\'m trying to deep populate a collection.

For example

// UnitType.js
name: { type: \'string\' }

// Unit.js
unitType: {
  model: \'unitType\',
  via         


        
相关标签:
1条回答
  • 2021-01-06 07:23

    You could try to replace Waterline ORM with Offshore ORM. There is a hook for sails to do that - sails-hook-orm-offshore.

    It's quite easy to implement to your existing project, because its fork of Waterline wits some more features. Only cons i found is that sails-hook-validation stopped working.

    How to install

    npm install sails-hook-orm-offshore --save
    

    Configuration

    .sailsrc

    {
        "hooks": {
            "orm": false,
            "pubsub": false
        }
    }
    

    Defaults

    config/globals.js

    adapters: true,
    models: true
    

    Usage

    Now you will be allowed to deep populate in your queries. For example (from documentation):

    User.find()
    .populate('foo.bar', { name: 'foo' }) //populate foo into user and bar into foo
    .exec(function(err, users) {
        console.log(users[0].foo.bar.name) // 'foo'
    });
    

    Second option

    Merge deep populate with waterline

    npm i Atlantis-Software/waterline#deepPopulate
    
    0 讨论(0)
提交回复
热议问题