Doctrine 1
  1. Doctrine 1
  2. DC-589

refreshRelated() causes an id to be changed from string to int, causing an unnecessary update query.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Record
    • Labels:
      None
    • Environment:
      Ubuntu 9.10, PHP 5.2.10, pgsql 8.3

      Description

      Here is an example:

      class Article extends Doctrine_Record
      {
          public function setTableDefinition()
          {
              $this->hasColumn('title', 'string', 255);
              $this->hasColumn('body', 'string', 4096);
          }
      
          public function setUp()
          {
              $this->hasMany('Comment as Comments', array(
                  'local' => 'id',
                  'foreign' => 'articleId',
              ));
          }
      }
      
      class Comment extends Doctrine_Record
      {
          public function setTableDefinition()
          {
              $this->hasColumn('comment', 'string', 4096);
              $this->hasColumn('articleId', 'integer');
          }
      
          public function setUp()
          {
              $this->hasOne('Article', array(
                  'local' => 'articleId',
                  'foreign' => 'id',
              ));
          }
      
          public function preUpdate($e)
          {
              throw new Exception('should not get here');
          }
      
      }
      
      $a = new Article();
      $a->title = 'Hi';
      $a->body = 'There';
      $a->save();
      
      $c = new Comment();
      $c->comment = '1st comment';
      $c->articleId = $a->id;
      $c->save();
      
      $a->refreshRelated('Comments');
      
      $a->title = 'Hello';
      $a->save();
      

      What happens above is that the call to refreshRelated() causes the 'id' of the comment to change from string:1 to int:1, which causes the last save of the article to try to save the comment. The exception is there just to illustrate that the Comment is being updated (which should not happen). For us - this is an issue not just because of the extra query, but because some entities in the system (like log entries) actually throw when updated.

      Tested against latest trunk.

      The issue seems to be introduced in r7361.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        How does that revision cause the problem? it doesn't change any value that is referenced by the object itself. Are you sure the description of the problem is accurate? Maybe it would be best if I could run a Doctrine failing test case to see your problem.

        Show
        Jonathan H. Wage added a comment - How does that revision cause the problem? it doesn't change any value that is referenced by the object itself. Are you sure the description of the problem is accurate? Maybe it would be best if I could run a Doctrine failing test case to see your problem.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Emil Vladev
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: