Just and update that in Admin.php I have this but still no success. please
advise.

$metadata->mapManyToMany(array('fieldName' => 'departments',
                               'targetEntity' => 'HdDepartment',
                      //         'cascade' => array('persist','merge'),
                               'inversedBy' => 'admins', //
                               'joinTable' => array( 'name' =>
'admin_hddepartment',
                                                      'schema' => NULL,
                                                      'joinColumns' =>
array( 0 => array( 'name' => 'admin_id',

'referencedColumnName' => 'admin_id',

'nullable' => true,

'columnDefinition' => NULL,

),),
                                                     'inverseJoinColumns'
=> array( 0 => array( 'name' => 'hddepartment_id',

'referencedColumnName' => 'id',

'nullable' => true,

'onDelete' => 'cascade',

'columnDefinition' => NULL,

), ),
                                                     ),
                               )
                         );

On Sat, Oct 14, 2017 at 12:41 AM, Nima Sadjadi <[email protected]> wrote:

> Hello,
>
> Many admins may have many departments.
>
> in Admin.php I have:
>
>   $metadata->mapManyToMany(array( 'fieldName' => 'departments',
>                                                 'targetEntity' =>
> 'HdDepartment',
>                                                 'cascade' =>
> array('persist','merge'),
>                                                 'inversedBy' => 'admins'
>                                               )
>                                         );
>
> in HdDepartment.php I have:
>
> $metadata->mapManyToMany(array('fieldName' => 'admins',
>                                'targetEntity' => 'Entities\\Admin',
>                                'cascade' => array('persist', 'merge'),
>                                'mappedBy' => 'departments'
>                               )
>                          );
> When I delete a department, the relation in admin_to_hddepartment join
> table is deleted too and admin is NOT deleted, this is fine until now.
> But when I delete admin, only admin itself is deleted, I don't want
> department will be deleted in this case and it is not as expected, still
> fine, but the relation remains in join table and it would be something
> orphan.
> How to delete this orphan record from admin_to_hddepartment join table?
>
> Thanks,
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to