Skip to content

Circular dependency issue regarding model relationships #227

@kouak

Description

@kouak

As of now, when defining a relationship in a Model class, the documentation states this :

    // The related model. This can be either a Model
    // subclass constructor or an absolute file path
    // to a module that exports one. We use the file
    // path version in this example to prevent require
    // loops.

Setting a string pointing to the file where the dependant model feels more like a workaround than a proper solution.

I've seen this issue tackled in graphql-js using thunks. See here : graphql/graphql-js#373

My proposal is to allow the developer to write this :

import RelationModel from './RelationModel';

export default class MyModel extends Model {
/* ... */
  static relationMappings = {
    relation: {
      modelClass: () => RelationModel,
    },
  };
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions