Doctrine 1
  1. Doctrine 1
  2. DC-198

refreshRelated inserts records when One-to-One relationships are used and a related record is deleted

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.5
    • Fix Version/s: 1.2.0-RC1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Mac OS X, PHP 5.2.11, MySQL 5.1.37

      Description

      When one-to-one relationship is used and a refreshRelated is performed after a delete a new record is inserted with NULL values.

      schema.yml

      Email:
      columns:
      user_id: integer
      address: string(150)
      relations:
      User:
      local: user_id
      foreign: id
      type: one
      foreignType: one
      foreignAlias: email

      User:
      columns:
      name: string(150)

      Sample code

      Create.php - create the user/email

      $u = new User();
      $u->name = 'Test';
      $u->email->address = 'foo@bar.com';
      $u->save();

      Delete.php - remove the email

      $u = Doctrine_Query::create()>from('User')>fetchOne();
      $u->name = 'Test2' ;
      $u->email->delete();
      $u->refreshRelated('email');
      $u->save();

      The profile (of Delete.php)

      connect 0.005211

      query 0.000493
      SELECT u.id AS u_id, u.name AS u_name FROM user u
      prepare 0.000028
      SELECT e.id AS e_id, e.user_id AS euser_id, e.address AS e_address FROM email e WHERE e.user_id = ?
      execute 0.001086
      SELECT e.id AS e_id, e.user_id AS euser_id, e.address AS e_address FROM email e WHERE e.user_id = ?
      Array
      (
      [0] => 1
      )
      Total time: 0.00681829452515
      fetch 0.000024
      SELECT e.id AS e_id, e.user_id AS euser_id, e.address AS e_address FROM email e WHERE e.user_id = ?
      fetch 0.000016
      SELECT e.id AS e_id, e.user_id AS euser_id, e.address AS e_address FROM email e WHERE e.user_id = ?
      begin 0.000147

      prepare 0.000019
      DELETE FROM email WHERE id = ?
      execute 0.000253
      DELETE FROM email WHERE id = ?
      Array
      (
      [0] => 1
      )
      Total time: 0.00727772712708
      commit 0.001120

      prepare 0.000021
      SELECT e.id AS e_id, e.user_id AS euser_id, e.address AS e_address FROM email e WHERE e.user_id = ?
      execute 0.000333
      SELECT e.id AS e_id, e.user_id AS euser_id, e.address AS e_address FROM email e WHERE e.user_id = ?
      Array
      (
      [0] => 1
      )
      Total time: 0.0087513923645
      fetch 0.000017
      SELECT e.id AS e_id, e.user_id AS euser_id, e.address AS e_address FROM email e WHERE e.user_id = ?
      begin 0.000104

      prepare 0.000020
      UPDATE user SET name = ? WHERE id = ?
      execute 0.000291
      UPDATE user SET name = ? WHERE id = ?
      Array
      (
      [0] => Test2
      [1] => 1
      )
      Total time: 0.00918316841125
      prepare 0.000021
      INSERT INTO email (id, user_id, address) VALUES (?, ?, ?)
      execute 0.000193
      INSERT INTO email (id, user_id, address) VALUES (?, ?, ?)
      Array
      (
      [0] =>
      [1] =>
      [2] =>
      )
      Total time: 0.00939726829529
      commit 0.000823

      a var_dump of $u->toArray() after refreshRelated shows

      array(3) {
      ["id"]=>
      string(1) "1"
      ["name"]=>
      string(7) "Test2"
      ["email"]=>
      array(3)

      { ["id"]=> string(1) "1" ["user_id"]=> string(1) "1" ["address"]=> string(8) "foo@bar.com" }

      }

      And in the database I have null values for the email record.

      This does not happen if I change the relationship to hasMany

        Activity

        Hide
        Jonathan H. Wage added a comment -

        Any update on this? I am still trying to produce the problem but everything is working for me in my tests. I want to get this fixed in RC1 by this friday if a issue really exists.

        Show
        Jonathan H. Wage added a comment - Any update on this? I am still trying to produce the problem but everything is working for me in my tests. I want to get this fixed in RC1 by this friday if a issue really exists.
        Hide
        Mario Bittencourt added a comment -

        Hi Jon,

        I'll be able to take another look today (at night) so I'd probably will have an update by tomorrow.

        Regards.

        Show
        Mario Bittencourt added a comment - Hi Jon, I'll be able to take another look today (at night) so I'd probably will have an update by tomorrow. Regards.
        Hide
        Jonathan H. Wage added a comment -

        Any update? Can we chat in IRC or something to help try and find the problem?

        Show
        Jonathan H. Wage added a comment - Any update? Can we chat in IRC or something to help try and find the problem?
        Hide
        Mario Bittencourt added a comment -

        Hi,

        I've attached the test file you've requested. I hope this helps.

        Tested: 419 test cases.
        Successes: 4333 passes.
        Failures: 2 fails.
        Number of new Failures: 0

        Doctrine_Ticket_DC198_TestCase..................................................failed

        Doctrine_Ticket_DC198_TestCase : method testRemoveEmail failed on line 32
        Value1: 0
        !=
        Value2: 3

        Doctrine_Ticket_DC198_TestCase : method testRemoveEmail failed on line 36

        Show
        Mario Bittencourt added a comment - Hi, I've attached the test file you've requested. I hope this helps. Tested: 419 test cases. Successes: 4333 passes. Failures: 2 fails. Number of new Failures: 0 Doctrine_Ticket_DC198_TestCase..................................................failed Doctrine_Ticket_DC198_TestCase : method testRemoveEmail failed on line 32 Value1: 0 != Value2: 3 Doctrine_Ticket_DC198_TestCase : method testRemoveEmail failed on line 36
        Hide
        Jonathan H. Wage added a comment -

        Thanks. As soon as I ran the test case I saw the problem and could fix it much much faster Thanks a lot!!

        Show
        Jonathan H. Wage added a comment - Thanks. As soon as I ran the test case I saw the problem and could fix it much much faster Thanks a lot!!

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Mario Bittencourt
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: