Rachmat Chang
Rachmat Chang

Reputation: 197

Doctrine (Symfony3) Catchable Fatal Error: Argument 1 passed to (bundle) must be an instance of (bundle), array given

I have a problem in symfony or doctrine. I have an entity notificationsettinggroupdetail and notificationsettinggroup.

Notificationsettinggroup and notificationsettinggroup is master detail and have a join condition in entity doctrine.

The problem comes to me when I want to remove data detail from master (notificationsetinggroup) using:

    /**
 * Remove notificationSettingGroupDetail
 *
 * @param \Dsp\DspAdministrationBundle\Entity\notificationSettingGroupDetail $notificationSettingGroupDetail
 */
public function removeNotificationSettingGroupDetail(notificationSettingGroupDetail $notificationSettingGroupDetail)
{
    $this->NotificationSettingGroupDetail->removeElement($notificationSettingGroupDetail);
}

but when i use this, i got some error:

Catchable Fatal Error: Argument 1 passed to Dsp\DspAdministrationBundle\Entity\notificationSettingGroup::removeNotificationSettingGroupDetail() must be an instance of Dsp\DspAdministrationBundle\Entity\notificationSettingGroupDetail, array given, called in C:\xampp\htdocs\Symfony-DspWebApp\src\Dsp\DspAdministrationBundle\Controller\Api\ApiNotificationSettingGroupController.php on line 122 and defined

this is code in controller:

$entityDetailDelete = $this->getDoctrine()->getRepository(notificationSettingGroupDetail::class)->findNotificationGroupSettingDetailByMaster($userOld[$i]['id']);
$entity->removeNotificationSettingGroupDetail($entityDetailDelete);

where is my fault?

Upvotes: 0

Views: 456

Answers (1)

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

You are passing an array not the entity, if you don't want to edit the controller try this:

public function removeNotificationSettingGroupDetail(array $notificationSettingGroupDetails)
{
    foreach (notificationSettingGroupDetails as notificationSettingGroupDetail) {
        $this->NotificationSettingGroupDetail->removeElement($notificationSettingGroupDetail);
    }
}

Instead if you want to change the controller try this (if is implemented):

findOneNotificationGroupSettingDetailByMaster

instead of this:

findNotificationGroupSettingDetailByMaster

because findNotificationGroupSettingDetailByMaster returns an array not a single entity

Upvotes: 1

Related Questions