Sails.js Model: create 2 association to self failed

后端 未结 1 963
醉酒成梦
醉酒成梦 2021-01-05 11:43

I\'m pretty new on Nodejs and sails. I\'m implementing a server which is similiar to Twitter. In user model, there should be 2 fields: follower and following, and the 2 fiel

相关标签:
1条回答
  • 2021-01-05 12:13

    For such usage your model definition is incorrect, namely the via keywords. As per the waterline associations docs the via keyword references the other side of the association. So, for a follower the other side is following and vice-versa. In other words:

    follower: {
      collection: 'user',
      via: 'following'
    },
    following:{
      collection: 'user',
      via: 'follower'
    }
    

    You can check a full working example at: https://github.com/appscot/sails-orientdb/blob/master/test/integration-orientdb/tests/associations/manyToMany.selfReferencing.js

    0 讨论(0)
提交回复
热议问题