Skip to content

Explore ways to prevent relationships from creating dependency cycles #294

@joelalejandro

Description

@joelalejandro

Using direct resource imports to set the type in a relationship can produce a dependency cycle.

// book.ts
import Author from './author';

class Book extends Resource {
  static schema = {
    attributes: {
      title: String;
    },
    relationships: {
      authors: {
        hasMany: true,
        type: () => Author
      }
    }
  }
}
// author.ts
import Book from './book';

class Author extends Resource {
  static schema = {
    attributes: {
      firstName: String;
      lastName: String;
    },
    relationships: {
      books: {
        hasMany: true,
        type: () => Book
      }
    }
  }
}

We might want to replace type: () => Resource with a string resolver to prevent this and use resourceFor() to resolve the type internally.

We can accept both syntaxes to prevent this from becoming a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions