I have table products_items_colors
but colors in array PHP - both column is primary key.
In table is fields:
products_item_id - int
color -int
$color = [
1 => 'Black',
2 => 'Green',
3 => 'Blue',
];
Form is:
echo $this->Form->control('products_items_colors._ids', [
'type' => 'select',
'multiple' => true,
'options' => [
1 => 'Black',
2 => 'Green',
3 => 'Blue',
],
]);
In model ProductsItems
table
$this->hasMany('ProductsItemsColors', [
'foreignKey' => 'products_item_id',
]);
In model ProductsItemsColors
table
$this->setTable('products_items_colors');
$this->setDisplayField(['color', 'products_item_id']);
$this->setPrimaryKey(['color', 'products_item_id']);
$this->belongsTo('ProductsItems', [
'foreignKey' => 'products_item_id',
'joinType' => 'INNER',
]);
After save form - patch entity does not contain items. But if I put data into the database, the form shows me the values.
How do I save this data to a table?