ember.js - Router and DS model with belongsTo throws confusing exception -



ember.js - Router and DS model with belongsTo throws confusing exception -

my router keeps throwing next exception:

error while processing route: study assertion failed: can add together 'location' record relationship error: assertion failed: can add together 'location' record relationship

ds models:

app.location = ds.model.extend({ street: ds.attr('string'), city: ds.attr('string'), area: ds.attr('string'), lat: ds.attr('string'), lng: ds.attr('string'), report: ds.belongsto('report', {embedded: 'load'}) }); app.report = ds.model.extend({ title: ds.attr('string'), description: ds.attr('string'), reg_num: ds.attr('string'), location_str: ds.attr('string'), location: ds.belongsto('location', {embedded: 'load'}) });

and router:

app.reportroute = ember.route.extend({ model: function () { homecoming this.store.createrecord('report', { title: '', description: '', reg_num: '', location_str: '', location: { street: '', city: '', area: '', lat: '', lng: '' } }); }, setupcontroller : function(controller, model){ controller.set("model", model); } });

in above code utilize location record belongs report.

the interesting thing if alter location location in app.report:

location: ds.belongsto('location', {embedded: 'load'})

the error disappears. why? i'm still defining location property within report in router, expected same error.

the problem location appears capital letter in request:

{ "report": { "title":"asd", "description":"asdasd", "reg_num":"", "location_str":"novi sad", "location":null } }

how set models location in request sent server?

edit

model saving:

app.reportcontroller = ember.objectcontroller.extend({ actions: { savereport: function(record) { if (!this.get('title')) { alert('title empty'); } else { var self = this, study = this.store.createrecord('report', { title: this.get('title'), description: this.get('description'), reg_num: this.get('reg_num'), location_str: this.get('location_str'), location: this.store.createrecord('location', { street: this.get('street'), city: this.get('city'), area: this.get('area'), lat: this.get('lat'), lng: this.get('lng') }) }); console.log(report); report.save().then(function (result) { self.transitiontoroute('list'); }); } } } });

the error you're seeing because in study route model hook, you're setting location property on study record javascript object literal instead of ember info model.

you need instead:

model: function () { homecoming this.store.createrecord('report', { title: '', description: '', reg_num: '', location_str: '', location: this.store.createrecord('location', { street: '', city: '', area: '', lat: '', lng: '' }), }); },

the error goes away when alter "location" because it's no longer trying utilize object ember info model.

as far how ember info utilize capitalized location key, create serializer study model , override normalizepayload hook transform location key.

ember.js ember-data

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -