Sails.js Associations many-to-many relation

2019-04-15 19:03发布

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

0条回答
登录 后发表回答