Backbone-relational icon indicating copy to clipboard operation
Backbone-relational copied to clipboard

binding views automatically to newly created child models. What am I missing?

Open 0xgeert opened this issue 11 years ago • 3 comments
trafficstars

After a long struggle I finally located the issue I was having to the fact that on save of the parent-model NEW child models are created.

In my app this means that childviews will be bound to orphaned childmodels once the new child models are created. (Of course) I want my child views to keep referencing the respective newly created model instead.

imho this seems such a common usecase that I hope I must be missing something trivial to keep my childviews bound to the newly created childmodels automatically.

What's the best practice to approach this?

0xgeert avatar Dec 13 '13 20:12 0xgeert

What do you mean by this exactly? Do you have a code snippet? The new child models aren't just created out of thin air I guess?

PaulUithol avatar Jan 21 '14 13:01 PaulUithol

If the child models are in a collection on the parent model and are created on the server because the parent got saved, maybe findModel is what you're looking for? Just added that last week.

PaulUithol avatar Jan 21 '14 13:01 PaulUithol

"he new child models aren't just created out of thin air I guess?" Well, it's a been some time so I don't recall exactly, but I believe the creation of the new child models is done by Backbone-Relational upon save of the parentmodel.

Posted a question on SO a month ago which goes into a bit more detail

http://stackoverflow.com/questions/20547088/backbone-relational-save-creates-new-child-models-which-results-in-childviews-b

0xgeert avatar Jan 21 '14 14:01 0xgeert