Ticket #1105 (closed defect: fixed)

Opened 13 months ago

Last modified 12 months ago

Sluggable and indexes

Reported by: lucassus Owned by: jwage
Priority: minor Milestone:
Component: Attributes Version: 0.11.0
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description

Probably I found serious bug in Sluggable Listener:

in Doctrine_Template_Sluggable I've found:

$this->index('sluggable', array('fields' => $indexFields,
                                            'type' => 'unique'));

It means that index name is hard coded. When I try add sluggable to more than one model, postgres throws error:

[2008-06-04 17:20:11.137 CEST] sigma_development LOG:  statement: CREATE UNIQUE INDEX sluggable ON gallery.categories (slug)
[2008-06-04 17:20:11.137 CEST] sigma_development ERROR:  relation "sluggable" already exists

I'm using doctrine 0.10.4, bu I found the same error in 0.11.0.

Index name should be passed through options, eg.

$this->index($this->_options['index_name'], array('fields' => $indexFields,
                                            'type' => 'unique'));

Change History

Changed 13 months ago by lucassus

Fixed version of this class:

class Doctrine_Template_Sluggable extends Doctrine_Template
{
    /**
     * Array of timestampable options
     *
     * @var string
     */
    protected $_options = array('name'       =>  'slug',
                                'index_name' =>  'sluggable',
                                'type'       =>  'string',
                                'length'     =>  255,
                                'unique'     =>  true,
                                'options'    =>  array(),
                                'fields'     =>  array(),
                                'uniqueBy'   =>  array(),
                                'uniqueIndex'=>  true
    );

    /**
     * __construct
     *
     * @param string $array
     * @return void
     */
    public function __construct(array $options)
    {
        $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
    }

    /**
     * setTableDefinition
     *
     * @return void
     */
    public function setTableDefinition()
    {
        $this->hasColumn($this->_options['name'], $this->_options['type'], $this->_options['length'], $this->_options['options']);

        if ($this->_options['unique'] == true && $this->_options['uniqueIndex'] == true && ! empty($this->_options['fields'])) {
            $indexFields = array($this->_options['name']);
            $indexFields = array_merge($indexFields, $this->_options['uniqueBy']);
            $this->index($this->_options['index_name'], array('fields' => $indexFields,
                                            'type' => 'unique'));
        }

        $this->addListener(new Doctrine_Template_Listener_Sluggable($this->_options));
    }
}

Changed 13 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [4476]) fixes #1105

Changed 12 months ago by anonymous

  • milestone 0.11.3 deleted

Milestone 0.11.3 deleted

Note: See TracTickets for help on using tickets.