У меня есть 4 таблицы Порядок, LineItem, Shipment, ShipmentQuantity , имеющие некоторые отношения между ними, которые указаны ниже
ShipmentQuantity таблица и ее взаимосвязь
// order table column
static get jsonSchema() {
return {
type: 'object',
required: ['shipmentId', 'lineItemId', 'quantity'],
properties: {
id: { type: 'number' },
shipmentId: { type: 'number' },
lineItemId: { type: 'number' },
quantity: { type: 'number' },
},
};
}
// table relation-ship
static get relationMappings() {
return {
lineItem: {
relation: Model.BelongsToOneRelation,
modelClass: __dirname + '/LineItem',
join: {
from: 'ShipmentQuantity.lineItemId',
to: 'LineItem.id',
},
},
shipment: {
relation: Model.BelongsToOneRelation,
modelClass: __dirname + '/Shipment',
join: {
from: 'ShipmentQuantity.shipmentId',
to: 'Shipment.id',
},
},
};
}
}
Отгрузка таблица и ее отношения
// Shipment table column
static get jsonSchema() {
return {
type: 'object',
required: ['orderId', 'status'],
properties: {
id: { type: 'number' },
orderId: { type: 'number' },
},
};
}
// table relation-ship
static get relationMappings() {
return {
shipmentQuantities: {
relation: Model.HasManyRelation,
modelClass: __dirname + '/ShipmentQuantity',
join: {
from: 'Shipment.id',
to: 'ShipmentQuantity.shipmentId',
},
},
};
}
LineItem таблица и ее отношения
static get jsonSchema() {
return {
type: 'object',
properties: {
id: { type: 'number' },
orderId: { type: 'number' },
quantitySupplied: { type: 'number' },
name: { type: 'string' },
amount: { type: 'number' },
currency: { type: 'string' },
},
};
}
static get relationMappings() {
return {
order: {
relation: Model.BelongsToOneRelation,
modelClass: __dirname + '/Order',
join: {
from: 'LineItem.orderId',
to: 'Order.id',
},
},
shipmentQuantities: {
relation: Model.HasManyRelation,
modelClass: __dirname + '/ShipmentQuantity',
join: {
from: 'LineItem.id',
to: 'ShipmentQuantity.lineItemId',
},
},
};
}
Заказ таблица и ее связь
static get jsonSchema() {
return {
type: 'object',
properties: {
id: { type: 'number' },
supplierId: { type: 'number' },
siteId: { type: 'number' },
supplierName: { type: 'string' },
comment: { type: 'string' },
orderRef: { type: 'string' },
total: { type: 'number' },
purchaseOrderNumber: { type: 'string' }
},
};
}
static get relationMappings() {
return {
lineItems: {
relation: Model.HasManyRelation,
modelClass: __dirname + '/LineItem',
join: {
from: 'Order.id',
to: 'LineItem.orderId',
},
},
shipments: {
relation: Model.HasManyRelation,
modelClass: __dirname + '/Shipment',
join: {
from: 'Order.id',
to: 'Shipment.orderId',
},
},
orderShipments: {
relation: Model.HasManyRelation,
modelClass: __dirname + '/OrderShipments',
join: {
from: 'Order.id',
to: 'OrderShipments.orderId',
},
},
};
}
В соответствии с вышеприведенным отношением я пытаюсь получить некоторые данные для определенного заказа с определенным идентификатором заказа, и запрос задается как показано ниже
Order.query()
.joinEager('[shipments.shipmentQuantities.lineItem, lineItems.shipmentQuantities]')
.findById(id);
Это дает мне ошибку при потере подключения к среде разработки, в то время как аналогичный запрос, если я заменю joinEager на eager , тогда он будет отлично работать в среде разработки. Может кто-нибудь сказать мне, что это из-за joinEager и eager, тогда какая разница между ним? или что-то еще, что я пропустил