Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added failing tests for saving embedded records #578

Closed

Conversation

NilsLattek
Copy link

Creating a new record and adding a new embedded record will result in two requests (embedded: 'always'):

  • One POST request for the parent with the child record embedded
  • One POST request for child record

The second request is not necessary, because the child is embedded in the first request.

Creating a new embedded record on an existing parent results in a POST request to the childs url. My understanding is that it should perform a PUT request to the parents' url with the child embedded.

@sandstrom
Copy link
Contributor

I can confirm this exact problem.

@NilsLattek have you found a workaround?

@NilsLattek
Copy link
Author

Not yet. It might be possible to solve this using the new dirtyRecordsForHasManyChange methods. I am guessing that there is still some work going on for embedded records.

@bobey
Copy link

bobey commented Jan 16, 2013

I have the exact same problem.
It seems to me that dirtyRecordsForHasManyChange can't solve the problem.
The problem is that the new embedded object is already in dirty state right after its creation with createRecord().
I can't find a way to remove it from its dirty state.

There is also a question on SO:
http://stackoverflow.com/questions/14320925/how-to-make-embedded-hasmany-relationships-work-with-ember-data/14362629

@sandstrom
Copy link
Contributor

@bobey I think a newly created record (embedded or not) should be in a dirty state. I think the real problem here is that persistence is handled by separately for each record, instead of through the parent.

  • For an existing parent record and a new embedded record, saving should result in a PUT for the parent record (with the embedded record inside it).
  • When both the parent and embedded child are new, a single POST for the parent should occur.

In both cases, persistence is handled through the parent.

That said, I don't know exactly how to fix this, my understanding of the inner workings of ember data isn't deep enough.

@bobey
Copy link

bobey commented Jan 16, 2013

@sandstrom I just tested this one and it fixes the bug: https://github.com/emberjs/data/pull/629/files

@megpha
Copy link

megpha commented Jan 21, 2013

worked for me : https://github.com/emberjs/data/pull/629/files

@NilsLattek
Copy link
Author

The first problem was fixed in: 3b91851

@igorT
Copy link
Member

igorT commented Apr 6, 2013

Seems to be fixed.

@igorT igorT closed this Apr 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants