[Catalyst] create model

gdewitt gdewitt at goldstarlearning.com
Fri Jan 30 21:40:40 GMT 2009

Hi, I am using Catalyst, DBIx and postrges.  My tables have primary keys. 
When you create a primary key in postres a unique index is implicitly
created as well.  So the majority of my tables have a constraint that looks
like this: 

  CONSTRAINT table_pkey PRIMARY KEY (id)

I use catalyst to create my DBIx table definitions like this:

create.pl model MyModel ....

The resulting DBIx table definitions reflect the primary key as well as the
unique constraint like this:

__PACKAGE__->add_unique_constraint("table_pkey", ["id"]); 

So if I write a query like this:

    my $result = $c->model('Schema::Table')->find( 'x' );

it results in the following SQL:

SELECT x,y,z FROM table me WHERE (  ( me.id = 'x' ) OR ( me.id = 'x' )  );

This is happening because the 'find' function checks all the unique
constraints on the table, and in this case there are 2 ('primary' : 'id' and
'table_pkey' : 'id')

I can get around this by writing my query like this:

    my $result = $c->model('Schema::Table')->find( { 'id'=> 'x' }, {
'key'=>'primary' } );

But that is a pain.

Does anyone know a way that I can stop the 2nd unique constraint:

__PACKAGE__->add_unique_constraint("table_pkey", ["id"]); 

from being generated in my table definition files?

View this message in context: http://www.nabble.com/create-model-tp21503833p21503833.html
Sent from the Catalyst Web Framework mailing list archive at Nabble.com.

More information about the Catalyst mailing list