从hasMany关系中删除子项

Aar*_*oir 8 ember.js ember-data

如何在不删除子项的情况下从hasMany关系中删除子项?

我已经尝试将子项的foreign_key设置为null.我也尝试在父关系上使用removeObject.

这是一个例子.

App.Invoice = DS.Model.extend
  lines: DS.hasMany('App.Line')

App.Line = DS.Model.extend
  invoice: DS.belongsTo('App.Invoice')

App.InvoiceController = Ember.Controller.extend
  removeLine: (line) ->
    @get('content.lines').removeObject(line)
    line.set('invoice', null)
    @get('store').commit()

App.InvoiceEditView = Ember.View.extend
  templateName: 'invoice'

App.LineView = Ember.View.extend
  tagName: 'tr'
  templateName: 'line'


#invoice template
<table>
    {{#each content.tasks}}
      {{view App.LineView}}
    {{/each}}
</table>

#line template
<td><a {{action "removeLine" view.context}}>remove</a></td>
<td>{{description}}</td>
<td>{{price}}</td>
<td>{{price}}</td>
Run Code Online (Sandbox Code Playgroud)

我目前正在使用

jquery 1.8.2
ember.js v1.0.pre-4
ember-data v11
Run Code Online (Sandbox Code Playgroud)

Aar*_*oir 1

看来将发票设置为空字符串是有效的。

 App.InvoiceController = Ember.Controller.extend
   removeLine: (line) ->
     @get('content.lines').removeObject(line)
     line.set('invoice', '')
     @get('store').commit()
Run Code Online (Sandbox Code Playgroud)