简短说明:ember数据已退出发送student_id作为student_id,而是将其作为学生发送:
{"iep"=>{"effective_on"=>"Wed, 20 Nov 2013 06:00:00 GMT", "includes_transportation"=>false, "transportation_trips"=>nil, "transportation_purpose"=>nil, "student"=>"1234"}}
详细信息版本:
我正在努力在6月份为现有的大型rails应用程序添加一个ember应用程序,但不得不放下它。我再次拾起它,但是从Ember V1.0.0-rc.5-80-gf54e8ef到V 1.1.3 + pre.e0ffbf84和Ember-data从V0.13-30到V1.1.0-beta的颠簸.3-4不止一些事情已经变得混乱。
目前的问题是保存belongsTo关联。
App..Router.map (match)->
@resource 'students', ->
@resource 'student', path: ':student_id', ->
@resource 'studentIeps', path: 'ieps', ->
@route 'new', path: 'new'
@resource 'studentIep', path: ':iep_id', ->
@resource 'studentIepGoals', path: 'goals', ->
@route 'new', path: 'new'
App.StudentIepsRoute = Ember.Route.extend
model: ->
@modelFor('student').get('ieps')
App.StudentIepRoute = Ember.Route.extend
model: (params)->
@store.find 'iep', params['iep_id']
App.StudentIepsNewRoute = Ember.Route.extend
setupController: (controller) ->
controller.set 'content', @store.createRecord('iep')
App.Iep = DS.Model.extend
effectiveOn: DS.attr('date')
includesTransportation: DS.attr('boolean')
transportationTrips: DS.attr('number')
transportationPurpose: DS.attr('string')
student: DS.belongsTo('student')
App.Student = DS.Model.extend
firstName: DS.attr('string')
lastName: DS.attr('string')
fullName: Ember.computed ->
@get("lastName") + ", " + @get("firstName")
.property("lastName", "firstName")
ieps: DS.hasMany('iep')
App.StudentIepsNewController = Ember.ObjectController.extend
needs: ['student']
createIep: ->
iep = @store.createRecord('iep')
iep.set('effectiveOn', new Date(@get('effectiveOn')))
iep.set('student', @get('controllers.student.model'))
@set('effectiveOn', '')
iep.save().then (model) ->
App.Router.router.transitionTo('studentIep', model)
当应用程序尝试保存Iep时,它会使用POST
命中服务器 {"iep"=>{"effective_on"=>"Wed, 20 Nov 2013 06:00:00 GMT", "includes_transportation"=>false, "transportation_trips"=>nil, "transportation_purpose"=>nil, "student"=>"1234"}}
哪个当然是炸弹
IepsController中的ActiveRecord :: AssociationTypeMismatch #create
学生(#70256213944300)预期,得到字符串(#70256139944060)
因为ember数据已退出发送student_id作为student_id,而是将其作为学生发送。
我在这里缺少什么?