search

Home  >  Q&A  >  body text

Symfony2 Doctrine association deletion problem

Entity NotifyOrderCreate

/**
 * @ORM\Column(type="bigint",options={"unsigned"=true})
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @ORM\OneToOne(targetEntity="Order", inversedBy="notifyCreate",cascade={"persist"})
 * @ORM\JoinColumn(name="order_id", referencedColumnName="id",onDelete="CASCADE")
 **/
private $order;

Entity Order

/**
 * @ORM\Column(type="bigint",options={"unsigned"=true})
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @ORM\OneToOne(targetEntity="NotifyOrderCreate", mappedBy="order")
 **/
private $notifyCreate;

Find out that NotifyOrderCreate will also delete the order when executing remove. Please tell me how to break it.

習慣沉默習慣沉默2885 days ago649

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 16:46:12

    I don’t understand how to write comments. Given below is the yml code:

    oneToOne:
        order:
            targetEntity: SomeEntity
            joinColumn:
                name: some_id
                referencedColumnName: pk_id
                nullable: true
                onDelete: SET NULL
    

    This way of writing will set the field to NULL when deleting.

    reply
    0
  • Cancelreply