Is it necessary to use DS.hasMany
pointing to a DS.Model
when a model contains an array? Even if the array elements are not really models (no IDs o
Interestingly all the other 4 answers to this question have almost identical deserialize and serialize functions, so you could simplify things down to:
import Em from 'ember'
import DS from 'ember-data'
# Presumably based on these answers: http://stackoverflow.com/questions/12168570/how-to-represent-arrays-within-ember-data-models
# All we need to do is always make sure an array is returned from serialize or deserialize
toArray = (data) ->
switch Em.typeOf(data)
when 'array' then data
when 'string' then JSON.parse(data)
else []
export default DS.Transform.extend
deserialize: toArray
serialize: toArray
This is using ember-cli-coffees6 for coffeescript with import/export
support