1

I would like to be able to create nested models at the same time in backbone. I know how to use backbone relational to create the parent model. Then once it is saved, I can create child models through backbone relational. However, I want to be able to create both the parent and child models at the same time, which might not be possible because I can only create the child model once the parent model has already been created.

For example, let's say I was creating a forum like the one from the awesome backbone relational tutorial - http://antoviaque.org/docs/tutorials/backbone-relational-tutorial/. I would want to create a thread and a message at the same time(through the click of a single button) rather than create a thread then a message. Is this possible? Is there a better way of doing this that I'm not thinking of?

jebek
  • 63
  • 3
  • 1
    checked this? http://stackoverflow.com/a/7263647/1358004 – Viral Shah Nov 09 '12 at 09:43
  • I did look at it, but I don't think it answered my question. When it adds a child model, the parent model has already been created. What I'm looking for is something that can create both at the same time. – jebek Nov 09 '12 at 09:59
  • I think the most important bit is what is your back-end server? You can create your JSON and send it up and save everything on the server. The problem you will face is that the "children" objects will be sent out nested in the parent object but without a `parent_id` property, so on the server you will have to save them at different times... In rails this is easily done with `accept_nested_attributes_for` but every server tech has its own method I can imagine. – Tallmaris Nov 09 '12 at 11:36
  • yea, i tried using accept_nested_attributes_for(using rails), but the problem was creating a backbone model and updating my collection. I can't seem to do those things while using accept_nested_attributes_for – jebek Nov 09 '12 at 17:34
  • What problem are you trying to solve that creating one and then immediately creating the other, doesn't resolve? – Jon Biz Nov 09 '12 at 17:50
  • I guess i'm just trying to make it more convenient for the user to do it all in one action. For example, if I were creating a forum with threads and messages like in the backbone-relational tutorial, when the user creates a thread, he should be able to make the first message at the same time rather than taking two steps to do it. – jebek Nov 09 '12 at 19:10

1 Answers1

0

Found https://github.com/powmedia/backbone-forms .

It worked perfectly for me.

jebek
  • 63
  • 3