ember-decorators / ember-decorators/ember-decorators

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

Open
#422 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
357
Forks
93
PR merge metrics
No merged PRs in 30d

Description

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:
```javascript
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:

```javascript
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the LessonReservationModel definition and the cancelable mixin shown in the issue, then compare the native-class and traditional Model.extend forms. Reproduce the polymorphic cancellation relationship error and determine whether the behavior belongs to ember-decorators or Ember Data. Done means the native-class model is recognized as implementing cancelable, or the issue is narrowed to the responsible project.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.