[Dbix-class] DBIx::Class::Index::Simple

Peter Rabbitson rabbit+list at rabbit.us
Wed Apr 2 07:50:02 BST 2008


Mark Lawrence wrote:
> On Tue Apr 01, 2008 at 08:35:38PM -0500, Jonathan Rockway wrote:
>> * On Tue, Apr 01 2008, Peter Rabbitson wrote:
>>
>>>  __PACKAGE__->add_columns(
>>>    id => { data_type => 'integer', is_auto_increment => 1 },
>>>    starts_at => { data_type => 'datetime' },
>>> -  created_on => { data_type => 'timestamp' }
>>> +  created_on => { data_type => 'timestamp', index_as => 'created_test_simple_idx' }
>>>  );
>> The problem with this syntax is that you can only index one column.  Why
>> not do:
>>
>>   __PACKAGE__->add_index( idx_foo_bar => [qw/foo bar/] );
> 
> How often do you need to know the name of an index? Why not go one
> simpler and do:
> 
>     __PACKAGE__->add_index(qw/foo bar/);
> 
> Which could return the autogenerated name of the index. If you need the
> name at a later (more dynamic stage perhaps) then maybe expose the
> name generating method as well.
> 

When you generate several indexes per table, you need to be in full control of 
naming so no clashes will occur. In the above example what would be the index 
name? foo_bar? what if foo_bar is an indexed column too?




More information about the DBIx-Class mailing list