1

I'm having a really hard time getting backbone-relational to work correctly.

The problem is simple to understand (now I've tracked it down):

  • on save of the parentmodel NEW child models are created
  • from that point forward childviews that were bound to existing child models, keep referencing these child models which are now orphaned.
  • from then forward every change from a child view gets populated to it's corresponding orphaned model, which of course doesn't cascade to the parent model anymore.

Of course I want the childviews to link to the active childmodel instead of the orphaned one. I could go hacking something together that on each save, rebinds the views to the newly created models, but this seems such a normal use-case that I feel I must be missing something completely trivial.

How on earth do I just keep these childviews bound automatically to the correct childmodels?

(as an aside, it looks completely unnecessary to me for backbone-relational to be making new childmodels on save to begin with (instead of updating the existing ones). Without this, all would be working normally.. pfff)

Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
  • I'm having a similar problem, am using a similar approach (rerendering new views to the model and its new children) but also feel that that can't really be the right way. If you figure it out, please post your answer here -- I'll do the same. Also, is your "save" of the parentmodel only in Backbone or is your app doing a REST create which sends back new models (with IDs, etc)? – JP Slavinsky Dec 13 '13 at 16:52
  • If I were to have proper relations I would now probably take a look at https://github.com/jj-studio/Backbone-JJRelational which is really new, but at least does in place changes of models instead of creating new ones. (It explicitly talks about this distinction on the github page) I've tested it and it works. – Geert-Jan Dec 13 '13 at 20:31

0 Answers0