首页 > 编程学习 > Sails:Waterline多对多查询
2015九月11

Sails:Waterline多对多查询

Sys_user.js

module.exports = {
  schema: true,
  autoCreatedAt: false,
  autoUpdatedAt: false,
  attributes: {
    id: {
      type: 'integer',
      autoIncrement: true,
      primaryKey: true
    },
    roles: {
      collection: 'Sys_role',
      via: 'users'
    }
  }
};

Sys_role.js

users: {
      collection: 'Sys_user',
      via: 'roles'
      //dominant: true 
    },

 

使用populate查询

    Sys_role.findOne(1).populate('users').populate('menus').exec(function(err, role) {
      console.log(':::'+JSON.stringify(role.users));
      console.log(':::'+JSON.stringify(role.menus));
    });

 

1,540 total views, 2 views today

本文地址:https://blog.wizzer.cn/archives/3173 , 转载请保留.

One Response to “Sails:Waterline多对多查询”

  1. #1 shoutleaf 回复 | 引用 Post:2016-04-20 21:54

    看懂了

发表评论