1.4.0 would include cart_id key automatically
1.5.0 doesnt
const userCart = await Cart.query()
.where('user_id', 10)
.eager('items')
.first();
await userCart
.$relatedQuery('items')
.upsertGraph([{
// cart_id: 1 <--- set automatically by objection in 1.4.0
product_id: 100,
quantity: 2,
}]);
export default class Cart extends BaseModel {
static tableName = 'cart';
id: number;
user_id: number;
items: CartItem[];
static relationMappings = (): RelationMappings => ({
items: {
relation: Model.HasManyRelation,
modelClass: CartItem,
join: {
from: 'cart.id',
to: 'cart_item.cart_id',
},
},
})
}
export default class CartItem extends BaseModel {
static tableName = 'cart_item';
id: number;
cart_id: number;
product_id: number;
quantity: number;
}
upsertGraph is not supposed to work like that. If it did work previously, it was a bug/accidental feature. There's this issue that will cause this scenario to throw in the future.
Ok thanks for quick reply
@koskimas it would be nice to highlight this in the docs for upsertGraph. I was always under the impression it's similar to how inserts work as demonstrated in the docs:

That's what this issue is for https://github.com/Vincit/objection.js/issues/933
that might explain a bug or two actually :pensive:
Most helpful comment
That's what this issue is for https://github.com/Vincit/objection.js/issues/933