-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
feat(core): allow specifying custom pivot table entity #2901
Conversation
B4nan
commented
Mar 13, 2022
Codecov Report
@@ Coverage Diff @@
## master #2901 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 193 193
Lines 11764 11770 +6
Branches 2715 2716 +1
=========================================
+ Hits 11764 11770 +6
Continue to review full report at Codecov.
|
```ts @manytomany({ entity: () => Product, pivotEntity: () => OrderItem }) products = new Collection<Product>(this); ```
Is this supposed to add another column specified in the OrderItem entity to the pivot table? |
Full example is in the docs: https://mikro-orm.io/docs/collections#custom-pivot-table-entity The Or if you can think of some public API that would allow sorting thru the pivot properties, I am not against it, I just don't see how it could be configured. |
If I add the LocationMedium entity to the entiies array it will error. If I don't add it to the entities array it doesn't change anything in the pivot table though. I think that's how it's stated in the docs. @Entity()
export class LocationMedium {
@ManyToOne({ primary: true })
location: Location;
@ManyToOne({ primary: true })
medium: Medium;
@Property({ default: 1 })
prop: number;
}
// location.entity.ts
@Entity()
export class Location extends OmputBaseEntity {
@Property()
title: string;
...
@OneToMany(() => Event, courseDate => courseDate.location, { nullable: true })
event?: Event[];
@ManyToMany({ entity: () => Medium, nullable: true, pivotEntity: () => LocationMedium })
media?: Medium[];
} |
The entity indeed needs to be discovered. You need to specify the type in decorator options (unless you are using ts-morph): @ManyToOne(() => Location, { primary: true })
location: Location;
@ManyToOne(() => Medium, { primary: true })
medium: Medium; Will fix the examples, I am planning to use the code tabs there as well, to show the definition with entity schema as well. |
Note that this is wrong too, you need to use
|
Its not broken, the index needs to be rebuild on algolia after each version is published. It happens once a week, will see if I can trigger it manually. edit: fixed |