ember.js - Ember Data relationships being overwritten -
i've run problem on 2 separate instances both same problem. first here models 1 instance of problem:
host:
minicron.host = ds.model.extend({ hostname: ds.attr('string'), name: ds.attr('string'), created_at: ds.attr('date'), jobs: ds.hasmany('job') });
job:
minicron.job = ds.model.extend({ name: ds.attr('string'), command: ds.attr('string'), created_at: ds.attr('date'), host: ds.belongsto('host') });
the json job model receives:
{ "jobs":[ { "id":"94e81ce07cec25451ce711fce3d96bea", "name":"uname -a", "command":"uname -a", "created_at":"2014-03-10t16:25:08z", "host":{ "id":8, "hostname":"lucid32", "name":"lucid32", "created_at":"2014-03-08t18:13:52z" }, "executions":[ { "id":406, "job_id":"94e81ce07cec25451ce711fce3d96bea", "host_id":8, "created_at":"2014-03-09t18:15:28z", "started_at":"2014-03-09t18:15:28z", "finished_at":"2014-03-09t18:15:28z", "exit_status":0 } ] } ] }
and json host model receives is:
{ "hosts":[ { "id":8, "hostname":"lucid32", "name":"lucid32", "created_at":"2014-03-08t18:13:52z", "jobs":[ { "id":"94e81ce07cec25451ce711fce3d96bea", "name":"uname -a", "command":"uname -a", "host_id":8, "created_at":"2014-03-10t16:25:08z" } ] } ] }
the problem i'm having when host model loaded job model's host relationship seems overwritten. presume because in json each job host has has host_id param , ember replacing existing data knows host nothing. api sinatra app using activerecord , activemodel serialize models json don't have easy way remove host_id response.
it's worth noting i'm using custom serializer here http://mozmonkey.com/2013/12/loading-json-with-embedded-records-into-ember-data-1-0-0-beta/, couldn't ember recognise sideloaded data without it.
i've been trying figure out few days , i'm out of ideas :(
let me know if have questions , if helps full source app on github https://github.com/jamesrwhite/minicron/tree/master/lib/minicron/hub
thanks!
you add active model serializers gem sinatra app , remove host_id response:
class jobserializer < activemodel::serializer attributes :created_at, :started_at, :finished_at, :exit_status end
Comments
Post a Comment