{
"name": "TypeError"
"message": "Cannot read property 'tablePath' of undefined",
"stack": "TypeError: Cannot read property 'tablePath' of undefined\n at C:\\working\\Hianfa\\Hianfa\\api\\src\\query-builder\\SelectQueryBuilder.ts:1500:76\n at Array.map (<anonymous>)\n at SelectQueryBuilder.createJoinExpression (C:\\working\\Hianfa\\Hianfa\\api\\src\\query-builder\\SelectQueryBuilder.ts:1462:57)\n at SelectQueryBuilder.getQuery (C:\\working\\Hianfa\\Hianfa\\api\\src\\query-builder\\SelectQueryBuilder.ts:54:21)\n at SelectQueryBuilder.QueryBuilder.getQueryAndParameters (C:\\working\\Hianfa\\Hianfa\\api\\src\\query-builder\\QueryBuilder.ts:392:28)\n at SelectQueryBuilder.<anonymous> (C:\\working\\Hianfa\\Hianfa\\api\\src\\query-builder\\SelectQueryBuilder.ts:1948:40)\n at step (C:\\working\\Hianfa\\Hianfa\\api\\node_modules\\tslib\\tslib.js:136:27)\n at Object.next (C:\\working\\Hianfa\\Hianfa\\api\\node_modules\\tslib\\tslib.js:117:57)\n at C:\\working\\Hianfa\\Hianfa\\api\\node_modules\\tslib\\tslib.js:110:75\n at new Promise (<anonymous>)"
}
I am getting this error, while trying to map two tables with the mapping table.
VENDOR MODEL (TABLE 1)
@ManyToMany(type => VendorToCategory, vendorToCategory => vendorToCategory.vendor)
// @JoinColumn({name: 'vendor_vendor_category_id'})
public vendorToCategory: VendorToCategory[];
VENDOR CATEGORY MODEL (TABLE 2)
@ManyToMany(type => VendorToCategory, vendorToCategory => vendorToCategory.vendorCategory)
@JoinColumn({name: 'vendor_vendor_category_id'})
public vendorToCategory: VendorToCategory[];
MAPPING TABLE (VENDOR TO CATEGORY)
@ManyToMany(type => Vendor, vendor => vendor.vendorToCategory)
@JoinColumn({ name: 'vendor_id' })
public vendor: Vendor[];
@ManyToMany(type => VendorCategory, vendorCategory => vendorCategory.vendorToCategory)
@JoinColumn({ name: 'vendor_category_id' })
public vendorCategory: VendorCategory[];
Please help me out with this error!
Your problem is related to the wrong use of the @JoinColumn
decorator; you should use @JoinTable
while working with @ManyToMany
relationships.
So, instead of this:
@ManyToMany(type => VendorToCategory, vendorToCategory =>
vendorToCategory.vendorCategory)
@JoinColumn({name: 'vendor_vendor_category_id'})
public vendorToCategory: VendorToCategory[];`
You should write:
@ManyToMany(type => VendorToCategory, vendorToCategory => vendorToCategory.vendorCategory)
@JoinTable({
name: "vendor_vendor_category_id",
joinColumn: {
name: "vendorCategory",
referencedColumnName: "id"
},
inverseJoinColumn: {
name: "vendor",
referencedColumnName: "id"
}})
public vendor: Vendor[];`
The TypeORM docs aren't that specific when it comes to deal with relations, but they do provide some useful examples. So take a look at them if you want a detailed answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With