skobkin
PHP
2017.01.11 03:25
// Doctrine orphanRemoval=true query test
 
public function testAction()
{
    /** @var EntityManager $em */
    $em = $this->getDoctrine()->getManager();
    $em->beginTransaction();
    $user = new User('100000', 'user100000');
    $subUser1 = new User('100001', 'user100001');
    $subUser2 = new User('100002', 'user100002');
    $subUser3 = new User('100003', 'user100003');
    $sub1 = new Subscription($user, $subUser1);
    $sub2 = new Subscription($user, $subUser2);
    $sub3 = new Subscription($user, $subUser3);
    foreach ([$user, $subUser1, $subUser2, $subUser3, $sub1, $sub2, $sub3] as $entity) {
        $em->persist($entity);
    }
    $em->flush();
    $em->commit();
    $em->beginTransaction();
    $user->removeSubscriber($sub2);
    $user->removeSubscriber($sub3);
    $em->flush();
    $em->commit();
    $em->beginTransaction();
    foreach ([$user, $subUser1, $subUser2, $subUser3, $sub1, $sub2, $sub3] as $entity) {
        $em->remove($entity);
    }
    $em->flush();
    $em->commit();
    return new Response('done');
}
 
/*
START TRANSACTION
 
INSERT INTO users.users (id, login, name, created_at, updated_at) VALUES (?, ?, ?, ?, ?)
Parameters: [1 => 100000, 2 => user100000, 3 => null, 4 => 2017-01-11 00:19:23, 5 => null]
 
INSERT INTO users.users (id, login, name, created_at, updated_at) VALUES (?, ?, ?, ?, ?)
Parameters: [1 => 100001, 2 => user100001, 3 => null, 4 => 2017-01-11 00:19:23, 5 => null]
 
INSERT INTO users.users (id, login, name, created_at, updated_at) VALUES (?, ?, ?, ?, ?)
Parameters: [1 => 100002, 2 => user100002, 3 => null, 4 => 2017-01-11 00:19:23, 5 => null]
 
INSERT INTO users.users (id, login, name, created_at, updated_at) VALUES (?, ?, ?, ?, ?)
Parameters: [1 => 100003, 2 => user100003, 3 => null, 4 => 2017-01-11 00:19:23, 5 => null]
 
 
INSERT INTO subscriptions.subscriptions (author_id, subscriber_id) VALUES (?, ?)
Parameters: [1 => 100000, 2 => 100001]
 
INSERT INTO subscriptions.subscriptions (author_id, subscriber_id) VALUES (?, ?)
Parameters: [1 => 100000, 2 => 100002]
 
INSERT INTO subscriptions.subscriptions (author_id, subscriber_id) VALUES (?, ?)
Parameters: [1 => 100000, 2 => 100003]
 
COMMIT
 
START TRANSACTION
 
COMMIT
 
START TRANSACTION
 
DELETE FROM subscriptions.subscriptions WHERE author_id = ? AND subscriber_id = ?
Parameters: [0 => 100000, 1 => 100001]
 
DELETE FROM subscriptions.subscriptions WHERE author_id = ? AND subscriber_id = ?
Parameters: [0 => 100000, 1 => 100002]
 
DELETE FROM subscriptions.subscriptions WHERE author_id = ? AND subscriber_id = ?
Parameters: [0 => 100000, 1 => 100003]
 
 
DELETE FROM users.users WHERE id = ?
Parameters: [0 => 100000]
 
DELETE FROM users.users WHERE id = ?
Parameters: [0 => 100001]
 
DELETE FROM users.users WHERE id = ?
Parameters: [0 => 100002]
 
DELETE FROM users.users WHERE id = ?
Parameters: [0 => 100003]
 
COMMIT
*/