Skip to content

Extending a model breaks one-to-many relationship #2487

@navels

Description

@navels

We're running into issues around polymorphism upgrading our app to v3 and I think I've found a bug.

I took the one-to-many twiddle from this blog post and

  • subclassed the author model with robot.js

Just that one thing, without actually creating any robots or robot books, etc., was enough to break the linkage of books back to authors:

{
  "authors": [
    {
      "name": "John Steinbeck",
      "bookIds": [
        "1",
        "2",
        "3"
      ],
      "id": "1"
    }
  ],
  "books": [
    {
      "title": "Of Mice and Men",
      "authorId": null,
      "id": "1"
    },
    {
      "title": "The Grapes of Wrath",
      "authorId": null,
      "id": "2"
    },
    {
      "title": "Travels with Charley",
      "authorId": null,
      "id": "3"
    }
  ],
  "robots": []
}

Here is my twiddle showing this behavior:

A workaround is to repeat the association on the derived model:

import Author from './author';
import { hasMany } from 'ember-cli-mirage';
export default Author.extend({
  books: hasMany()
});

or use this form to create books:

server.create('book', {
  author,
  title: 'Of Mice and Men'
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions