Skip to content

Uncaught TypeError: parent.$fields()[key] is undefined When inserting nested data with polymorphic relationships  #1635

@tintin10q

Description

@tintin10q

Reproduction

Example 1

Example 2

Describe the bug

I am getting Uncaught TypeError: parent.$fields()[key] is undefined when inserting nested data in a polymorphic relationship. If I define the same relationship as a non polymorphic relationship (of course with only one repo) the error does not occur.

Something that is also weird is that the error seems to depend on which model the data is inserted from. Look at this:

This raises the error:

function save_person() {
  person.save({
    id: "pp",
    job: "dev",
    articles: [
      {
        type: "saved",
        item_id: "a",
        item_type: Article.entity,
        person_id: "pp",
        person_type: "person",
        item: {
          id: "a",
          name: "helllo?",
        },},],});}

But this does not:

function save_saved_article() {
  saved.save({
    type: "saved",
    item_id: "a",
    item_type: Article.entity,
    person_id: "p",
    person_type: "person",
    person: {
      id: "pp",
      job: "dev",
      articles: [
        {
          type: "saved",
          item_id: "a",
          item_type: Article.entity,
          person_id: "pp",
          person_type: "person",
          item: {
            id: "a",
            name: "helllo?",
          },},],},});}

Even though the exact same person is being inserted.

Additional context

I managed to create a reproduction this time :)

At first I thought this was an issue with sti but then I saw that it also broke without sti. So sti is still bugfree 👍

I hope this is easy to fix or even better that I made a mistake. Because I think it is quite common to insert all the data through the user model like this.

Logs

Uncaught TypeError: parent.$fields()[key] is undefined
    idAttribute index.mjs:346
    getId index.mjs:29
    normalize index.mjs:35
    visit index.mjs:151
    normalizeValue index.mjs:95
    normalize index.mjs:108
    visit index.mjs:151
    normalize index.mjs:52
    normalize index.mjs:48
    visit index.mjs:151
    normalizeValue index.mjs:95
    normalize index.mjs:124
    normalize index.mjs:124
    visit index.mjs:151
    normalize index.mjs:52
    normalize index.mjs:48
    visit index.mjs:151
    normalize index.mjs:175
    normalize index.mjs:401
    process index.mjs:393
    save index.mjs:1057
    save index.mjs:1583
    savePerson TestPolyAHH.vue:86

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions