When I try to create a new record in my custom module I get the below mentioned error
Something went wrong while saving the item.Notice: Array to string conversion in /opt/lampp/htdocs/Magento225/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 3028
Admin field in Ui Component form
<field name="customer_group_ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string">Customer Groups</item>
<item name="dataType" xsi:type="string">number</item>
<item name="formElement" xsi:type="string">multiselect</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
<item name="source" xsi:type="string">catalog_rule</item>
<item name="dataScope" xsi:type="string">customer_group_ids</item>
</item>
<item name="options" xsi:type="object">Magento\CatalogRule\Model\Rule\CustomerGroupsOptionsProvider</item>
</argument>
</field>
Error is coming form the piece of code below , when I comment out this code it works fine.
if (!empty($data['customer_group_ids'])) {
$data['customer_group_ids'] = implode(',', $data['customer_group_ids']);
} else {
$data['customer_group_ids'] = '';
}
Below code is similar to the one mention above(customer_group_ids) and working fine and saves the records in database correctly .
if (!empty($data['cmspage_ids'])) {
$data['cmspage_ids'] = implode(',', $data['cmspage_ids']);
}else {
$data['cmspage_ids'] = '';
}
I have both the above pieces of code in my save.php one is working fine and the other is not! What causes this issue to happen?
Output of the Array:
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)