Doctrine 1
  1. Doctrine 1
  2. DC-640

Slugs aren't created when inserting/updating a table row

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: Sluggable
    • Labels:
      None
    • Environment:

      Description

      Basically the slug column doesn't get updated in spite of all fields being added correctly, as far as i can tell.
      It seems to be related to additional options because when i don't have either of the uniqueBy or canUpdate options specified, it just works.

      What's been missing is the 'slug' column value in the sql statements (providing 3 examples):

      2400 Query INSERT INTO `custom_category` (`block_id`, `name`) VALUES ('1', 'slug test')
      2526 Query INSERT INTO `custom_category` (`name`, `block_id`) VALUES ('please do work..', '1')
      2560 Query UPDATE `custom_category` SET `name` = 'still not ok' WHERE `id` = '12'
      

      The generated schema.sql includes the correct create table statement (it's also correctly inserted in the db):

      CREATE TABLE `custom_category` (
        `id` INT UNSIGNED AUTO_INCREMENT,
        `name` VARCHAR(255) NOT NULL,
        `block_id` INT UNSIGNED NOT NULL,
        `slug` VARCHAR(255),
        UNIQUE INDEX `custom_category_sluggable_idx` (`slug`, `block_id`, `name`),
        INDEX `block_id_idx` (`block_id`),
        PRIMARY KEY(`id`)
      ) ENGINE = INNODB;
      

      The schema.yml entry is the following:

      CustomCategory:
        connection: removed
        tableName: custom_category
        actAs:
          Sluggable:
            fields: [name]
            uniqueBy: [block_id, name]
            canUpdate: true
        columns:
          id:
            type: integer(4)
            unsigned: true
            notnull: true
            primary: true
            autoincrement: true
          name:
            type: string(255)
            notnull: true
          block_id:
            type: integer(4)
            unsigned: true
            notnull: true
        relations:
          Products:
            class: Product
            foreignAlias: CustomCategories
            refClass: ProductCustomCategory
          Block:
            class: Block
            local: block_id
            foreign: id
            foreignType: many
            foreignAlias: CustomCategories
            type: one
      

      And finally the appropriate auto generated base class (removed doc block):

      <?php
      // Connection Component Binding
      Doctrine_Manager::getInstance()->bindComponent('CustomCategory', 'removed');
      
      abstract class BaseCustomCategory extends aaDoctrineRecord
      {
          public function setTableDefinition()
          {
              $this->setTableName('custom_category');
              $this->hasColumn('id', 'integer', 4, array(
                   'type' => 'integer',
                   'unsigned' => true,
                   'primary' => true,
                   'autoincrement' => true,
                   'length' => '4',
                   ));
              $this->hasColumn('name', 'string', 255, array(
                   'type' => 'string',
                   'notnull' => true,
                   'length' => '255',
                   ));
              $this->hasColumn('block_id', 'integer', 4, array(
                   'type' => 'integer',
                   'unsigned' => true,
                   'notnull' => true,
                   'length' => '4',
                   ));
          }
      
          public function setUp()
          {
              parent::setUp();
              $this->hasMany('Product as Products', array(
                   'refClass' => 'ProductCustomCategory',
                   'local' => 'custom_category_id',
                   'foreign' => 'product_id'));
      
              $this->hasOne('Block', array(
                   'local' => 'block_id',
                   'foreign' => 'id'));
      
              $sluggable0 = new Doctrine_Template_Sluggable(array(
                   'fields' =>
                   array(
                    0 => 'name',
                   ),
                   'uniqueBy' =>
                   array(
                    0 => 'block_id',
                    1 => 'name',
                   ),
                   'canUpdate' => true,
                   ));
              $this->actAs($sluggable0);
          }
      }
      

        Activity

        Hide
        Christian Seaman added a comment -

        What is the code that you're using to generate the INSERT query?

        Show
        Christian Seaman added a comment - What is the code that you're using to generate the INSERT query?
        Hide
        Daniel König added a comment -

        just instantiating the object, calling the setters, followed by a save().

        it's related to the uniqueBy and canUpdate options, though - it works like a charm without these two.

        Show
        Daniel König added a comment - just instantiating the object, calling the setters, followed by a save(). it's related to the uniqueBy and canUpdate options, though - it works like a charm without these two.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Daniel König
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: