Ember Data有很多关于AMS的保存

时间:2014-06-14 07:08:57

标签: ember.js ember-data active-model-serializers

我有一个ember应用程序,有2个模型,其中包含hasMany选项。基本上他们有HABTM关系。我在后端rails REST API中有AMS。

这是

App.Group = App.Subject.extend
  name: DS.attr 'string'
  title: DS.attr 'string'
  groupDesc: DS.attr 'string'
  createdAt: DS.attr 'date'
  users: DS.hasMany 'user'
  selected:false
  members: (->
    users = @get('users')
    if users then users.get 'length' else 0
  ).property('users')

App.Subject = DS.Model.extend
  roleAssignments: DS.hasMany 'roleAssignment'

App.User = App.Subject.extend
  fname: DS.attr 'string', defaultValue:''
  lname: DS.attr 'string', defaultValue:''
  email: DS.attr 'string', defaultValue:''
  position: DS.attr 'string'
  isSuperAdmin: DS.attr 'boolean'
  groups: DS.hasMany 'group'

当我尝试创建像这样的对象时

user1 = @store.find(1)
user2 = @store.find(2)
role1 = @store.find(1)
role2 = @store.find(2)

roleAssignment1 = @store.createRecord('roleAssignment',{role:role1})
roleAssignment2 = @store.createRecord('roleAssignment',{role:role2})


group = @store.createRecord 'group', {name:'Test'}
group.get('users').pushObject(user1)
group.get('users').pushObject('user1)
group.get('roleAssignments').pushObject(roleAssignment1)
group.get('roleAssignments').pushObject(roleAssignment2)

When I save this group it posts the following into the server

group.save()

{"group":{"name":"Test","title":null,"group_desc":null,"created_at":null}}

其余数据在哪里。我认为按照https://github.com/kaukas/data/commit/d55a30e3c07139d8aa034dfffd535fccae512ce1,这个问题在AMS中为Ember数据解决了。

更新

由于某些原因(js缓存等),用户现在得到反映,但是role_assignments_id将作为role_assignment_ids:[“0”]

在将它附加到组

之前,我是否需要创建它?

0 个答案:

没有答案