Doctrine 1
  1. Doctrine 1
  2. DC-1057

Inserts instead of updates for related objects

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Relations
    • Labels:
      None
    • Environment:
      linux, apache2, php 5.3

      Description

      Ok, so the object relations go like this:

      • Comparison
        • [1:N] Product (FK:comparison_id)
          • [1:N] Rules (FK:product_id, FK:option_id)
          • [1:N] Parameters (FK:product_id)
            • [1:N] Options (FK:parameter_id)

      The testing code looks like following:

      == CODE START ==

      Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      $comp = new Application_Model_Comparison();
      
      /* Filling $comp with data */
      
      for ($i = 0; $i < 10; $i++) {
      
          $product = new Application_Model_Product();
      
          // Options referenced in Rules
          $options = array();
      
          for ($j = 0; $j < 10; $j++) {
      
              $param = new Application_Model_Parameter();
      
              for ($k = 0; $k < 10; $k++) {
      
                  $option = new Application_Model_Option();
      
                  $param->Options->add($option);
      
                  // Register a single option for this parameter
                  if (!isset($options[$j])) {
                      $options[$j] = $option;
                  }
              }
      
              $product->Parameters->add($param);
          }
      
          for ($j = 0; $j < 10; $j++) {
              $rule = new Application_Model_Rule();
      
              $rule->Option = $options[$j];
              $product->Rules->add($rule);
          }
      
          $comp->Products->add($product);
      }
      
      /**
       * The first save() goes nicely, all objects
       * are created (INSERTed)
       */ 
      
      $comp->save();
      
      // Remove every second product
      $pCount = $comp->Products->count();
      
      for ($i = 0; $i < $pCount; $i += 2) {
          $comp->Products->remove($i);
      }
      
      /**
       * Fails while trying to save
       *
       * Comparison->Product->Parameter->Option
       * INSERT ... `parameter_id` cannot be NULL
       *
       * Comparison->Product->Rule
       * INSERT ... `product_id` cannot be NULL
       */
      
      $comp->save();
      

      == CODE END ==

      The first save() cleans up the relation information in the graph. All child objects are INSERTED instead of UPDATE.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Grzegorz Godlewski
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: