У меня есть 2 коллекции ProductVariant и Inventory
module.exports = new EntitySchema({
name: 'ProductVariant',
target: ProductVariant,
columns: {
id: {
primary: true,
type: 'varchar',
},
image: {
type: 'json',
nullable: true,
},
productId: {
type: 'varchar',
},
},
relations: {
product: {
target: 'Product',
type: 'many-to-one',
joinColumn: {
name: 'productId',
},
},
inventory: {
target: 'Inventory',
type: 'one-to-one',
inverseSide: 'variantId',
cascade: true,
},
},
});
и инвентарь
const EntitySchema = require('typeorm').EntitySchema;
const Inventory = require('../models/inventory').Inventory;
module.exports = new EntitySchema({
name: 'Inventory',
target: Inventory,
columns: {
id: {
type: 'varchar',
primary: true,
unique: true,
},
sku: {
type: 'varchar',
nullable: true,
},
variantId: {
type: 'varchar',
}
},
relations: {
variant: {
target: 'ProductVariant',
type: 'one-to-one',
cascade: true,
joinColumn: {
name: 'variantId',
},
},
},
});
Теперь, если я выполню этот запрос
const products = await ProductRepo.find({ relations: ['collections', 'variants', 'variants.inventory'] });
Я получу сообщение об ошибкеCannot read property 'joinColumns' of undefined
В моей базе данных отношения выстроены идеально. Единственное, что здесь может быть неправильным, это то, что нет пути от варианта к инвентарю, но есть путь от инвентаря к варианту. Так что это не двусторонняя вещь. Только один к одному с одной стороны, но ORM должен был быть достаточно умен, чтобы правильно выбрать? Это единственная вещь здесь.
Может кто-нибудь сказать мне, как это исправить.