Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 711
user2590223 Avatar asked Dec 21 '13 09:12

user2590223


1 Answers

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

like image 75
sfb Avatar answered Oct 14 '22 13:10

sfb