Are embedded many to many relationships possible?


#1

A store can have many employees, and employees can have many stores. Model & Serializer for stores

export default DS.Model.extend({
    name: DS.attr('string'),
    address: DS.attr('string'),
    address2: DS.attr('string'),
    city: DS.attr('string'),
    state: DS.attr('string'),
    zip: DS.attr('string'),
    employees: DS.hasMany('employee')
});

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  isNewSerializerAPI: true,
  attrs: {
      employees: {
          serialize: 'records',
          deserialize: 'records'
      }
  }
});

Model & Serializer for employee

export default DS.Model.extend({
    firstName: DS.attr('string'),
    lastName: DS.attr('string'),
    stores: DS.hasMany('store'),
    name: Ember.computed('firstName', 'lastName', function() {
        return `${this.get('firstName')} ${this.get('lastName')}`;
    })
});

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  isNewSerializerAPI: true,
  attrs: {
      stores: {
          serialize: 'records',
          deserialize: 'records'
      }
  }
});

When I try to save Im getting an uncaught range error. I just want to save the store with a full list of employees in one object.

But on another page I want to save an employee and a list of stores which is why its a hasMany relationship.


#2

I also noticed that when you use serialize: 'ids' instead of serialize: 'records' I don’t see this error. So it is having a tough time going through a many to many relationship of embedded records and sending the full records up.

Has anyone done this before? Im just looking to see if its possible or not and I can work on it from there.