[Dbix-class] Q: Differing column names in DBIC and SQL

Peter Rabbitson rabbit+list at rabbit.us
Tue Oct 21 09:38:29 BST 2008


Bernhard Graf wrote:
> One common practice to avoid problems with reserved words in column (or 
> table) names is to prefix every name with an underscore.
> 
> Is there an elegant and working way in DBIC to accomplish this?
> 
> I already tried
> 
> __PACKAGE__->add_columns(
>   user => {
>     data_type => 'varchar',
>     name => '_user',
>   },
> );
> 
> and deploy() actually generated an SQL column "_user", but then failed 
> at the first
> 
> __PACKAGE__->add_unique_constraint(['user']);

Do not mutilate column names, but instead use your tools the way they
were intended to be:
http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/Storage/DBI.pm#quote_char

As a side note - it is wise to avoid naming columns identical to perl
conventional method names (i.e. having a column 'new' will have some
strange side effects)



More information about the DBIx-Class mailing list