how to use the attribute type like 'array' and 'json' in sails

為{幸葍}努か 提交于 2019-12-07 00:54:05

问题


Sails have support very convenient model througth Waterline, and I have used the 'array' attribute type in the way storing many string, but now I want to store more complex object, Although I can store the raw data in mongo by 'array' type, I don't know if it is safe and I want define the object type in the array, like mongoose's style. for example, I need a model "Products" and I want define it as a 'array' but the object stored in the array only model "Book", what I can do like this, but I don't think it works.

module.exports = {
  products : {
    type : 'array',
    Book : {
      name : 'string',
      price : 'integer'
    }
  }
}

So, any suggestion about use of the 'array' and 'json' is very appreciated, thanks so much!


回答1:


I don't think that the array type is going to work the way you want it to. What you're looking for is associations which will be available in SailsJS 0.10 (which you can get via git right now). The array attribute type for MySQL and PostgreSQL it will only stringify the array and store it as text in the database then it will parse the field when returning the value.

source



来源:https://stackoverflow.com/questions/20717628/how-to-use-the-attribute-type-like-array-and-json-in-sails

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