Trying to work through an issue with belongsToMany() where my pk is a string (similar to uuid)
simple products <-- product_productgroups --> productgroups
but products primary key on products is apk varchar(50)
when I use integer values, everything is fine, but if I use strings, they are converted to 0 when searching the pivot table:
$product = App\Products::with('productgroups')->find('B00AE38KM');
"select * from `products` where `products`.`apk` = ? limit 1"
array:1 [▼ 0 => "B00AE38KM" ]
"select productgroups.*, product_productgroup.product_apk as pivot_product_apk, product_productgroup.productgroup_id as pivot_productgroup_id from productgroups inner join product_productgroup on productgroups.id = product_productgroup.productgroup_id where product_productgroup.product_apk in (?)"
array:1 [▼ 0 => 0 ]
My Products model has:
public function productgroups()
{
return $this->belongsToMany('App\ProductGroups',
'product_productgroup',
'product_apk',
'productgroup_id');
}
TIA!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire