Sails.js Associations many-to-many relation

丶灬走出姿态 提交于 2019-12-06 13:43:36

问题


I have a problem with many to many relationship in sails and if somebody can help me it would be great :D

I have two models User and Message and the associations is defined as follows

api/models/User.js

module.exports = {
  attributes: {         
    messages: {
      collection: 'message',
      via: 'owner',
      dominant: true
    }
  }
};

api/models/Message.js

module.exports = {
  attributes: {
    owner: {
      model: 'user'.
      via: 'messages'
    }
  }
};

I checked in the DB (MySQL) the middle table is created and i successfully inserted the data but i cant retrive the data.

i start sails console and type

User
  .find()
  .populate('messages')
  .exec(function(err,r){
    while(r.length){
      var thisUser=r.pop();
      console.log(thisUser.toJSON())
    }
  });

But i always recive no data for messages, the messages field is always empty messages: []

my Current version of sails is 0.10.0-rc4

来源:https://stackoverflow.com/questions/22912599/sails-js-associations-many-to-many-relation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!