[Catalyst] create model

Robert Mah rmah at pobox.com
Sat Jan 31 15:25:29 GMT 2009


It really doesn't matter a whole lot.  Postgres will automatically optimize
out the duplicate where condition.  If you do an EXPLAIN query in the pgsql,
you'll see what I mean. 

Basically, it's just a little ugly in your log, but won't affect runtime
operations.

Cheers,
Rob

-----Original Message-----
From: gdewitt [mailto:gdewitt at goldstarlearning.com] 
Sent: Friday, January 30, 2009 4:41 PM
To: catalyst at lists.scsys.co.uk
Subject: [Catalyst] create model


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__->set_primary_key("id");
__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.


_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list