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

Christopher H. Laco claco at chrislaco.com
Wed May 23 00:21:08 GMT 2007


Bill Moseley wrote:
> This is suppose to be an ORM-neutral question.
>=20
> I often use lookup tables in the database, even for things like, say,
> cart_status:
>=20
>     create table cart_status (
>         id      SERIAL PRIMARY KEY,
>         name    text NOT NULL,
>         active  boolean NOT NULL DEFAULT TRUE
>     );
>=20
>     -- trust the sequence, Luke
>     insert into cart_status (name) values ('Pending');
>     insert into cart_status (name) values ('Completed');
>=20
> Then things like this are nice:
>=20
>     [% cart.cart_status.name %]
>=20
> And can do this:
>=20
>     update cart_status set name =3D 'Finished' where name =3D 'Complete=
d';
>=20
> And add new lookup options:
>=20
>     insert into cart_status (name) values ('Orphaned');
>=20
>=20
> but this is not so nice:
>=20
>     $cart_class->search( cart_status =3D> 1 );
>=20
>=20
> So, what have you found that works nicely?
>=20
>     use MyApp::Const qw/ cart_pending /;  # potentially long list
>     cart_status =3D> cart_pending  # runtime checking
>=20
>     use MyApp::Const qw/ :cart /; # Shorter list :)
>=20
>=20
>     cart_status =3D> MyApp::CONST::pending, # global constants
>=20
>=20
>     # Make it very clear where a constant should be used
>     # by adding the constants as methods to the cart namespace
>=20
>     cart_status =3D> $cart_class->pending_status
>=20
>=20
>=20
>=20
>=20


Why not just inflate/deflate into your own Status object?
Granted, that's not ORM neutral...

-------------- 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/284a3d3c/signature.pgp


More information about the Catalyst mailing list