-
-
Notifications
You must be signed in to change notification settings - Fork 43
Description
> @CodeDredd: i found out that everything works fine. You got an typo. One time you use "retailerCode" and in the rawData "retailer_code".
My issue was not the retailerCode or retailer_code.
The retailerId and supplierId should be different:
The result
supplierId: 1andretailerId: 16The index should be[16, 1]
This works great if a developer only uses one belongsToMany relation; like in your test.
class Client extends Model {
static entity = 'clients'
static fields () {
return {
id: this.number(0),
name: this.string(null),
retailers: this.belongsToMany(Client, ClientRetailer, 'supplierId', 'retailerId'),
}
}
}When we add a second "inversed" relation on the Client model. Because when we have a Client and we want to know if the Client has suppliers. Things go wrong.
class Client extends Model {
static entity = 'clients'
static fields () {
return {
id: this.number(0),
name: this.string(null),
retailers: this.belongsToMany(Client, ClientRetailer, 'supplierId', 'retailerId'),
suppliers: this.belongsToMany(Client, ClientRetailer, 'retailerId', 'supplierId')
}
}
}The retailerId and supplierId should still be different:
The result
supplierId: 1andretailerId: 16The index should still be[16, 1]
not[16,16]
What bothers me is that in the rawData the relation suppliers the data was never provided.
And it looks like despite the absense of data the relation was still called or filled.
Originally posted by @adm-bome in #1447 (comment)