sails js data relationship

跟風遠走 提交于 2019-12-24 04:17:49

问题


Does sails.js support relationships between models/collections? If so, can someone point to documentation?

For example: I have 2 models

1.Production

production: {
  name: 'string',
  description: 'text'
}

2.Album

album: {
  name: 'string',
  productionID: 'ObjectID'// How do I get to "production"?
}

回答1:


Sailsjs 0.9.x does not support relationships or associations currently. 0.10 does have a rough outline of this working.

Disclaimer: the 0.10 branch is a constant work in progress and can break on a daily basis as the contributors push code to it, if somethings broken its best to ask in the irc #sailsjs chat or post an issue tagged 0.10 if it truly is broken.

You can install sailsjs v0.10 to give it a try by doing something like the following.. (I'm not in front of my machine to test this but it should work).

   #in your downloads directory or somewhere globally accessible clone the 0.10 branch
   git clone https://github.com/balderdashy/sails -b v0.10 sails;
   cd sails; npm install; npm link;
   #this will install all sails dependencies, and npm link sails to that cloned folder

Once its installed you can then run sails -v and you should get 0.10.

Then its just a matter of generating a new sails app with sails new <appname>




回答2:


Waterline, the ORM for Sails, does support associations between models/collections. However, support for associations is a work in progress. With that being said, the MySQL and Postgresql support is the furthest along.

You may find the unfinished documentation for waterline v0.10 here:

https://github.com/balderdashy/waterline-docs



来源:https://stackoverflow.com/questions/21366618/sails-js-data-relationship

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