updating the status of a hasMany relationship blows up #442

Closed
mehulkar opened this Issue Oct 29, 2012 · 3 comments

Comments

Projects
None yet
3 participants

Talked with @wycats about this. I was trying to embed a hasMany relationship on store commit and it wouldn't allow me to update the relationship on success. The difference between the two is the order. Currently you have to update the relationship before you update the record.

This fails:

createRecord: (store,type,record) ->
  root = @rootForType(type)
  data = {}
  data[root] = @toJSON(record, { includeId: true })
  posts = []

  record.get("posts").forEach (p) ->
    posts.pushObject p.toJSON()

  data[root]["posts"] = posts

  store = App.router.get('store')
  @ajax @buildURL(root), "POST", {
  data: data
  context: this
  success: (json) ->
    # this order is important
    @didCreateRecord(store,type,record,json)
    record.get('posts').forEach (p) ->
      store.didUpdateRelationship(p, 'author')
  }

## updating the relationship before calling `didCreateRecord` works
  success: (json) ->
    record.get('posts').forEach (p) ->
    store.didUpdateRelationship(p, 'author')
    @didCreateRecord(store,type,record,json)
Contributor

elliterate commented Nov 17, 2012

What error did you get?

I don't remember what the exact error was, but I think the either post or author didn't change it's inFlight state.

Owner

igorT commented Apr 15, 2013

A lot of this code has changed so closing due to inactivity. Happy to reopen if its still an issue.

igorT closed this Apr 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment