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

Polymorphic Inheritance #18

Open
Gonzalo9823 opened this issue Jul 29, 2021 · 1 comment
Open

Polymorphic Inheritance #18

Gonzalo9823 opened this issue Jul 29, 2021 · 1 comment

Comments

@Gonzalo9823
Copy link

Hi! I have a question regarding inheritance.

I have a Organization class (not an entity) and many entities that inherit from this class such as Grower, Company, Client, etc.

What I wan't to do is to have a UserOrganizationRole entity that polymorphically points to this different entities but when I add the PolymorphicChildren decorator to Organization it gives me the error "Class extends value undefined is not a constructor or null" this doesn't happen if a I add the decorator separately in every entity.

I'm doing something wrong or the library doesn't support the heritage of the PolymorphicChildren decorator?

Example:

This works:

export class Organization extends CustomBaseEntity {
  @Column({ unique: true })
  name!: string;
}
@Entity({ name: 'companies' })
export class Company extends Organization {
  @PolymorphicChildren(() => UserOrganizationRole, {
    eager: false,
  })
  users!: UserOrganizationRole[];
}
@Entity({ name: 'clients' })
export class Client extends Organization {
  @PolymorphicChildren(() => UserOrganizationRole, {
    eager: false,
  })
  users!: UserOrganizationRole[];
}

This doesn't works:

export class Organization extends CustomBaseEntity {
  @Column({ unique: true })
  name!: string;

  @PolymorphicChildren(() => UserOrganizationRole, {
    eager: false,
  })
  users!: UserOrganizationRole[];
}
@Entity({ name: 'companies' })
export class Company extends Organization {}
@Entity({ name: 'clients' })
export class Client extends Organization {}
@bashleigh
Copy link
Owner

that should work? Perhaps I've messed something up by not checking abstracts? Or defining to the prototype or something?

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

2 participants