Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
navels opened this issue Feb 5, 2023 · 0 comments
Open

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

navels opened this issue Feb 5, 2023 · 0 comments

Comments

@navels
Copy link

navels commented Feb 5, 2023

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'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant