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

Saving with EmbeddedRecordsMixin does not update related models dirty attributes #2487

Closed
DEfusion opened this issue Nov 18, 2014 · 10 comments
Closed

Comments

@DEfusion
Copy link

I created a demo (http://jsbin.com/zejala/6/edit?js,output) simulating saving hasMany related models via DS.EmbeddedRecordsMixin and Rails' accepts_nested_attributes_for.

No matter what way the serializer is configured in Ember dirty attributes of the relationships records are not updated with those from the response, non dirty attributes are updated though.

The only workaround I have found is to manually go through and mark them individually as willCommit and then didCommit by overriding save on the model - I tried doing this in the serializer for better encapsulation but couldn't get it to work.

If I've specified serialize: 'records' for my serializer when using EmbeddedRecordsMixin I would expect those records to be automatically set as saving/saved etc. along with the parent according to the normal save flow.

@jcope2013
Copy link
Contributor

this similar?

emberjs/rfcs#21

@DEfusion
Copy link
Author

@jcope2013 Yeah it's similar and I read that before I posted, but that seems generally to be concerned about the dirtiness of the parent when related models change. Though I note the later comments on savesRelationship/savesModel do cover this scenario a lot better emberjs/rfcs#21 (comment)

@lolmaus
Copy link
Contributor

lolmaus commented Feb 9, 2015

I ran into this issue, here's my story: http://stackoverflow.com/questions/28408274/how-to-update-child-records-in-the-store-when-parent-record-is-saved

The demo in top post broke due to some <script> tags linking to latest versions and others linking to fixed versions. Here's a working demo: http://jsbin.com/finax/1/edit?html,js,output

So, are there any updates on this one?

Also, is the manual method of updating child records kindly provided by @DEfusion an optimal one? It is so low-level that i'm kinda worried to use it. Is there a less hacky way?

@lolmaus
Copy link
Contributor

lolmaus commented Feb 10, 2015

I've resolved the issue for me and published the solution as an Ember CLI addon: https://github.com/lolmaus/ember-cli-stained-by-children

If it helps you, please star it.

PS This issue should not be considered resolved until it works out of the box.

@dogawaf
Copy link
Contributor

dogawaf commented May 24, 2015

I encounter this issue too. My usecase:

  • the action willTransition prevents the transition if the parent model or an embedded model is dirty
  • when the parent model is saved, a transition to the parent route need to be done
  • but the transition is aborted because the embedded model remains dirty

@perlun
Copy link

perlun commented May 25, 2015

👍, this should be fixed. It's definitely a bug with the mixin IMHO. I adapted the @lolmaus approach now (willCommit, clear _attributes, didCommit) but it definitely feels like a hack to have to do this manually.

/cc @emilgrip

@lolmaus
Copy link
Contributor

lolmaus commented May 25, 2015

Please send a PR containing a failing test case for this issue. It will be much easier to fix.

@perlun
Copy link

perlun commented May 25, 2015

Agree, it would be good. Any pointers/hints on how to start? (I've never worked with the ember data tests) Is it a regular ember-cli project?

@fidlip
Copy link

fidlip commented Aug 31, 2015

Hi guys, is there any progress?

@fivetanley
Copy link
Member

Please re-open (as a new issue if necessary), hopefully with a failing test case or JSBin. I suspect this has been fixed since 1.13. Sorry but we're triaging inactive issues. Re-opening lets us see if people are still running into them more easily.

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

No branches or pull requests

7 participants