(cake3) I’m trying to save data to a join table with the following code in the controller
foreach ( $this->request->data['glass_products']['_ids'] as $key => $value ) {
$this->request->data['glass_products']['_ids'][ (int) $key ] = array( 'id' => $value, '_joinData' => array( 'quantity' => (int) 99 ) );
}
$product = $this->Products->patchEntity( $product, $this->request->data );
But am getting a Cannot convert value to integer
error. Screenshot of error: http://bit.ly/2nekPMx
I’ve followed the table naming conventions (glass_products_products in this case) and the error only occurs when the _joinData is added to the request object.
GlassProductsProducts
class GlassProductsProductsTable extends Table {
public function initialize( array $config ) {
parent::initialize( $config );
$this->table( 'glass_products_products' );
$this->primaryKey( 'id' );
$this->belongsTo( 'GlassProducts' );
$this->belongsTo( 'Products' );
}
}
GlassProducts
```class GlassProductsTable extends Table {public function initialize( array $config ) {
parent::initialize( $config );`
$this->table( 'glass_products' );
$this->displayField( 'name' );
$this->primaryKey( 'id' );
$this->addBehavior( 'Timestamp' );
$this->hasMany( 'GlassOrders', [
'foreignKey' => 'glass_product_id'
] );
$this->belongsToMany( 'Products', [
'foreignKey' => 'glass_product_id'
] );
}
Products
class ProductsTable extends Table {
public function initialize( array $config ) {
parent::initialize( $config );
$this->table( 'products' );
$this->displayField( 'name' );
$this->primaryKey( 'id' );
$this->addBehavior( 'Timestamp' );
$this->hasMany( 'CustomerOrders', [
'foreignKey' => 'product_id'
] );
$this->belongsTo( 'ProductTypes', [
'foreignKey' => 'product_type_id'
] );
$this->belongsToMany( 'GlassProducts', [
'foreignKey' => 'product_id'
] );
}}
Can anyone help? I’m going round the houses with this one!