Ember and embedded records

I am working on a protoype where I use Ember. But I run into problems, when working with embedded records.

I have some json like so:

var facetList = [
        {
          'Alias' : 'WaterSaving',
          'DisplayName' : 'Vand besparende',
          'id':47,
          'Facets' : [
          { 
              'DisplayName' : 'false',
              'FacetId' : 47,
              'Value' : 'false',
              'id':0
          },
          { 'DisplayName' : 'true',
          'FacetId' : 47,
          'Value' : 'true',
          'id':1
      }
      ]
  },
  { 
      'Alias' : 'Type',
      'DisplayName' : 'Type',
      'id':48,
      'Facets' : [ 
      { 
          'DisplayName' : 'håndvask',
          'FacetId' : 48,
          'Value' : 'håndvask',
          'id':2
      },
      { 
          'DisplayName' : 'køkken',
          'FacetId' : 48,
          'Value' : 'køkken',
          'id':3
      }
      ]
  }
  ];

So the facetList has embedded facets in each item - these arrays are the ones I refer to as embedded records

As I understand from this blogpost and my own experience, ember does not work with embedded records.

I understand that ember is very opinionated, and that ember would like to work with normalized databases (that from the blogpost) However as I see it when working over for instance a restful API, it makes sense to denormalize the data again, in order to not make the API too chatty.

Do you consider making Ember work more friendly with embedded records? The thing is that this data will never be sent back to the server, so basically i just read and use it for filtering/searching, hence ember.data is not a goood fit for this…

By the way I have this SO if you would like to help me: ember.js - Ember, handlebars and arrays - Stack Overflow

Your embedded records have IDs, which means that they don’t have to be embedded. I would suggest writing your own serializer and separating the embedded records and making them standalone records. You’ll still have your embedded records on the server side, but Ember will never know.

Also, as a warning, your property names are capitalized and will not work with Ember Handlebars templates. Be sure your convert those names to lowercase in your models if you haven’t already.

1 Like

I second this. I actually had the same issue and decided to flatten all my JSON and gave everything IDs.