[Catalyst] CDBI, Mason, and null foreign keys

Alan Humphrey alan.humphrey at comcast.net
Wed Jul 20 23:51:14 CEST 2005


All -

 

I'm using CDBI (model) and Mason (view) for my application.  I like both but
I'm finding myself doing this a lot in my mason templates:

 

% print $c->stash->{source}->get('url_id')->get('url') if defined
$c->stash->{source}->get('url_id');

 

In other words, check that the object exists before trying to reference it.
In this example the 'sources' table has an optional column 'url_id' which
holds an id to the 'urls' table.  Using that id I want to return the actual
url.

 

This works just fine, but it seems a little verbose.

 

As an experiment I tried "flattening" the database results in the controller
so all the template sees is an array of hashes.  That worked as well and now
the clutter is in the controller.

 

Any opinions as to the better approach?  Any other approaches?  Is there a
better way to handle null foreign key references in CDBI?

 

- Alan

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20050720/5181baf2/attachment.htm


More information about the Catalyst mailing list