[Catalyst] Constants that refer to rows in a lookup table.

Christopher H. Laco claco at chrislaco.com
Wed May 23 00:37:14 GMT 2007


Bill Moseley wrote:
> This is suppose to be an ORM-neutral question.
> =

> I often use lookup tables in the database, even for things like, say,
> cart_status:
> =

>     create table cart_status (
>         id      SERIAL PRIMARY KEY,
>         name    text NOT NULL,
>         active  boolean NOT NULL DEFAULT TRUE
>     );
> =

>     -- trust the sequence, Luke
>     insert into cart_status (name) values ('Pending');
>     insert into cart_status (name) values ('Completed');
> =

> Then things like this are nice:
> =

>     [% cart.cart_status.name %]
> =

> And can do this:
> =

>     update cart_status set name =3D 'Finished' where name =3D 'Completed';
> =

> And add new lookup options:
> =

>     insert into cart_status (name) values ('Orphaned');
> =

> =

> but this is not so nice:
> =

>     $cart_class->search( cart_status =3D> 1 );

And just because you've mentioned cart... :-)
What's so wrong with cart_status =3D> 1 ?

..where cart_status in (1, 2)

Constants aren't the devil. MyApp::Constants isn't abnormal.

Personally, I never store 'flags' as strings. You say 'pending', I say
'Pending'....and if the db is or isn't case sensitive?...

IF you do store it as strings, I'd say still use constants in your code
anyways...

-=3DChris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070522/2e68=
60ab/signature.pgp


More information about the Catalyst mailing list