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

Christopher H. Laco claco at chrislaco.com
Wed May 23 00:37:42 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 );
> =

> =

> So, what have you found that works nicely?
> =

>     use MyApp::Const qw/ cart_pending /;  # potentially long list
>     cart_status =3D> cart_pending  # runtime checking
> =

>     use MyApp::Const qw/ :cart /; # Shorter list :)
> =

> =

>     cart_status =3D> MyApp::CONST::pending, # global constants
> =

> =

>     # Make it very clear where a constant should be used
>     # by adding the constants as methods to the cart namespace
> =

>     cart_status =3D> $cart_class->pending_status
> =

> =

> =

> =

> =


And why aren't you using Handel? :-)

-------------- 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/a1a6=
3787/signature.pgp


More information about the Catalyst mailing list