0

I'm using Ember.js 1.0 and Ember-Data 1.0beta. I have a model with a hasMany relationship:

Whistlr.Activity = DS.Model.extend
  participants: DS.hasMany('activityParticipant')

I would like the client to be able to add participants directly in the activity form, but I have no idea how to express this in the template. Specifically, how would I write the valueBindings? Something like:

Em.TextField valueBinding="participant[2].name"
nullnullnull
  • 8,039
  • 12
  • 55
  • 107

1 Answers1

2

The question right before yours is doing it:

http://jsbin.com/oDOsoqA/4/edit

There are a slew of things that may be appropriate for your situation. In this guys situation he is on the list model, and he renders all of the tasks on the list (which have things to edit on each one of them) etc.

{{render 'task' tasks}}
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • As far as I can tell, this approach is placing several sub-forms within a master-form. Whenever the client inputs data into a sub-form (such a comment), then that data is propagated immediately via the store. Is there a way to instead wait until the client has submitted the master-form to then submit all of the sub-forms, ideally as a nested json object? I suspect this really complicated, but if you know of an example, it'd appreciate a chance to look at the source. – nullnullnull Oct 28 '13 at 21:27
  • Instead of using a form to submit you can just use ember data (or model) and save the models on the master form save. What portion of Ember do you plan on really using? – Kingpin2k Oct 29 '13 at 00:08
  • I'm using Ember Data. When I base my form off the jsbin you provided, I'm able to create several child objects as expected. The problem is that when I submit the form, Ember doesn't send the data for these child objects, only for the parent. Any advice for nesting all this data into a single payload? – nullnullnull Oct 29 '13 at 01:35
  • Looks like this functionality isn't supported by Ember-Data yet. There are several ways to get it, though. If you're using ActiveModelSerializer (for Rails support), you can use the code [here](https://github.com/emberjs/data/issues/1426). If you're using the JSONAdapter or RESTAdapter, you can find code [here](http://stackoverflow.com/questions/19093078/ember-data-saving-record-loses-has-many-relationships). Either way, thanks for your help kingpin. It was essential for resolving the first half of this problem. – nullnullnull Oct 31 '13 at 00:07