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

        Grzegorz Godlewski created issue -
        Grzegorz Godlewski made changes -
        Field Original Value New Value
        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 ==

        $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.
        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 ==
        {{
        $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.
        Grzegorz Godlewski made changes -
        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 ==
        {{
        $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.
        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 ==
        {code:php}
        $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}
        == CODE END ==

        The first save() cleans up the relation information in the graph. All child objects are INSERTED instead of UPDATE.
        Grzegorz Godlewski made changes -
        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 ==
        {code:php}
        $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}
        == CODE END ==

        The first save() cleans up the relation information in the graph. All child objects are INSERTED instead of UPDATE.
        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 ==
        {code:php}
        $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}
        == CODE END ==

        The first save() cleans up the relation information in the graph. All child objects are INSERTED instead of UPDATE.
        Guilherme Blanco made changes -
        Affects Version/s 1.2.4 [ 10063 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-1057, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated: