ember-restless icon indicating copy to clipboard operation
ember-restless copied to clipboard

How do I save and retrieving string arrays embedded as a property of the object

Open reedyrm opened this issue 12 years ago • 2 comments

I'm working to model an object that has multiple embedded string arrays

App.Class = RL.Model.extend({
  id: RL.attr('string'),
  className: RL.attr('string'),
  teachers: RL.hasMany('string'),
  students: RL.hasMany('string')
});

It looks like everything is working, but when I display the Class object.

It looks like this: classobject

This is a snippet of my template:

     <h3 class="panel-title">Class Name: {{className}}</h3>
          </div>

          <div class="panel-body">
              <ul class="list-group">
                  <li class="list-group-item">
                      <div class="row">
                          <div class="col-md-2">Teachers:</div>
                          <div class="col-md-10">{{teachers}}</div>
                      </div>
                  </li>
                  <li class="list-group-item">
                      <div class="row">
                          <div class="col-md-2">Students:</div>
                          <div class="col-md-10">{{students}}</div>
                      </div>
                  </li>

Is there any special serialization/deserialization methods that I need implement in order to display it as a simple string both from the model and to the model when saving? And if so, where would those methods live?

Thanks

reedyrm avatar Jan 13 '14 20:01 reedyrm

@reedyrm if you just make those properties string attributes ( teachers: RL.attr('string') ), it will turn the array data into a string of comma separated values.

Also, you can omit the id attribute in your model, as its automatically added.

gpoitch avatar Jan 13 '14 20:01 gpoitch

Thanks for the quick response. That fixed my problem.

reedyrm avatar Jan 13 '14 20:01 reedyrm