tags:

views:

173

answers:

2

Is it possible to have multiple slugs on one table in Doctrine?

I tried this in my yaml-file:

Article:
  tableName: tst_article
  actAs:
     Sluggable:
       unique: true
       fields: [title]
       canUpdate: true
     Sluggable:
       unique: true
       fields: [text]
       name: secondSlug
  columns:
    id:
      type: integer(8)
      primary: true
      autoincrement: true
    category_id:
      type: integer(8)
    title:
      type: text(255)
    text:
      type: clob

But after generating the sql only the secondSlug was generated...

+3  A: 

It is possible. In your table definition write:

public function setUp() {
    parent::setUp();

    $sluggable0 = new Doctrine_Template_Sluggable(array(
        'fields' => array(0 => 'name'),
        'unique' => true,
        'canUpdate' => true
    ));
    $this->actAs($sluggable0);

    $sluggable1 = new Doctrine_Template_Sluggable(array(
        'fields' => array(0 => 'native_name'),
        'unique' => false,
        'canUpdate' => false,
        'name' => 'native_name_slug'
    ));
    $this->actAs($sluggable1);
}

The problem is in YAML itself. You have something like this:

keyA:
  keyB: value
  keyB: value

What might be translated into:

array(
    'keyA' => array(
        'keyB' => 'value',
        'keyB' => 'value'
    )
);

So as you see there is definition of keyB and then keyB is overwritten with new value. So in your YAML file second definition overrides the first one.

How to solve that? I don't know, but I'll do some researches. Right now you're forced to declare your models in pure PHP.

Crozin
A: 
Article:
  tableName: tst_article
  actAs:
     Sluggable:
       unique: true
       fields: [title, text]
       canUpdate: true
  columns:
    id:
      type: integer(8)
      primary: true
      autoincrement: true
    category_id:
      type: integer(8)
    title:
      type: text(255)
    text:
      type: clob
David Mann