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

Mixin pattern for polymorphic relationships doesn't seem to work with native classes

Open adambedford opened this issue 5 years ago • 1 comments

Polymorphic relationships in Ember require either inheritance from a common parent or a mixin (with the name of the polymorphic relationship) to be applied. I'm trying to get the mixin solution working with an Ember Data model that uses native classes, however it doesn't seem that the mixin is being recognized. Inspecting the model shows that the mixin's properties were applied to the model, however.

The error I'm seeing is:

The 'lesson-reservation' type does not implement 'cancelable' and thus cannot be assigned to the 'cancelable' relationship in 'cancellation'. Make it a descendant of 'cancelable' or use a mixin of the same name.

The model is LessonReservation and the polymorphic association is cancelable. There is a mixin named cancelable.

The native class syntax doesn't work:

import DS from 'ember-data';
import Cancelable from 'frontend/mixins/cancelable';

const { Model } = DS;

export default class LessonReservationModel extends Model.extend(Cancelable) {
}

However, the traditional syntax does work:

import DS from 'ember-data';
import Cancelable from 'frontend/mixins/cancelable';

const { Model } = DS;

export default Model.extend(Cancelable, {

})

It may be that I'm misattributing this issue to ember-decorators when it's a more core Ember issue but this seemed like a good place to start. Any guidance would be very appreciated.

adambedford avatar Mar 25 '19 04:03 adambedford

Just encountered this too.

Skwai avatar Mar 28 '23 05:03 Skwai