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

Bi-directional Relations between CustomEntities and VendureEnteties #2344

Closed
kefkalexis opened this issue Aug 11, 2023 · 2 comments
Closed

Comments

@kefkalexis
Copy link
Contributor

We want to create bi-directional relations between VendureEntities and our customEntites, for example:

@Entity()
export class MyCustomEntity extends VendureEntity {

  @ManyToMany(
    () => Collection,
    (c: Collection) => c.customFields?.theOtherSide,
  )
  public theOneSide: Collection[];
}

customFields.Collection = [
  {
    name: "theOtherSide",
    type: "relation",
    entity: MyCustomEntity ,
    list: true,
  },
]

We havn't found a solution to connet these both sides since typeOrm needs to know the jointable which is implicitly defined by vendure in registerCustomFieldsForEntity.

Describe the solution you'd like
We would propose to add the inverseSid-function used by typeorm as a field to the customFieldConfiguration:

customFields.Collection = [
  {
    name: "theOtherSide",
    type: "relation",
    entity: MyCustomEntity ,
    list: true,
    inverseSide: (x: MyCustomEntity ) => x.theOneSide,
  },
]

Describe alternatives you've considered
Another possibility would be to manipulate the typeOrm-metadata, but we would prefer to have it visible in the customField-definition

Additional context
If you agree with the proposal I could provide a pull request with the changes mentioned above

@michaelbromley
Copy link
Member

Hi,

Thanks for the report & proposal. Maybe this is a silly question, but why do you want to be able to define the inverse side? Is it so you can use the query builder API more conveniently when querying Collections and joining the custom relations?

I'd be happy to see a PR - if so make it against the minor branch please :)

@kefkalexis
Copy link
Contributor Author

Thanks for your response.

yes, it would make working with relations more convenient.

I created a pull request here: #2365

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