Skip to content

Error from ember data with the module model #1507

@AmauryD

Description

@AmauryD

Hello, while upgrading an addon, i got this error from ember-data :

Uncaught Error: The schema for the relationship 'component.components' is not configured to satisfy 'module' and thus cannot utilize the 'module.components' relationship to connect with 'class.implicit-module:components1700295419147'

If using this relationship in a polymorphic manner is desired, the relationships schema definition for 'component' should include:

{
  components: {
    name: 'components',
    type: 'class',
    kind: 'hasMany',
    options: {
      as: 'undefined', <---- should be 'module'
      async: false,
      polymorphic: false,
      inverse: 'implicit-module:components1700295419147'
    }
  }
}

 and the relationships schema definition for 'class' should include:

{
  implicit-module:components1700295419147: {
    name: 'implicit-module:components1700295419147',
    type: 'module',
    kind: 'implicit',
    options: {
      as: 'undefined', <---- should be 'class'
      async: false,
      polymorphic: false, <---- should be true
      inverse: 'components'
    }
  }
}

    at assertInheritedSchema (-private.js:423:1)
    at assertConfiguration (-private.js:656:1)
    at isLHS (-private.js:673:1)
    at Graph.get (-private.js:1685:1)
    at addToInverse (-private.js:1108:1)
    at replaceRelatedRecordsRemote (-private.js:1067:1)
    at replaceRelatedRecords (-private.js:946:1)
    at Graph.update (-private.js:1894:1)
    at updateRelationshipOperation (-private.js:1535:1)
    at Graph.update (-private.js:1863:1)

Doing a patch of the module model made it work:

diff --git a/addon/models/module.js b/addon/models/module.js
index 4887ba3bd30829653cd6944f1097ed65db41a9da..8c10bc597ef794f99e52549d0bef31eae12b08a1 100644
--- a/addon/models/module.js
+++ b/addon/models/module.js
@@ -13,7 +13,7 @@ export default class Module extends Model {
   @hasMany('class', { async: false, inverse: null })
   classes;
 
-  @hasMany('class', { async: false, inverse: null })
+  @hasMany('component', { async: false, inverse: null })
   components;
 
   /*

I don't really know if the components property of the module model should be of type 'component' or 'class'.

If you want to reproduce the error, here is the pull-request: RobbieTheWagner/ember-flatpickr#1911. You just need to remove

"pnpm": {
    "patchedDependencies": {
      "ember-cli-addon-docs@6.0.2": "patches/ember-cli-addon-docs@6.0.2.patch"
    }
  }

from the package.json.

I'd be happy to make a PR if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions