[Dbix-class] Alias column names
Eden Cardim
edencardim at gmail.com
Tue Apr 20 18:40:18 GMT 2010
On Tue, Apr 20, 2010 at 12:25 PM, Bill Moseley <moseley at hank.org> wrote:
> Is there a way in DBIC to alias column names? I know I can specify an
> accessor name (and create wrapper accessors using different names), but I'm
> looking for a way to alias column names to use both as accessors and when
> calling create().
> The deal is I already have a Catalyst app with a DBIx::Class model. I'm
> adding some API functionality but the specifications require using new names
> for some of the column data. So, in the same app I need to be able to do
> $schema->resultset( 'Cd' )->create({
> name => 'Frampton Comes Alive',
> artist => $artist,
> });
> And
> $schema->resultset( 'Cd' )->create({
> ttitle => 'Frampton Comes Alive',
> author => $artist,
> });
> And likewise, these are the same:
> $title = $cd->title;
> $title = $cd->name;
> as well as these has-many relationships:
> $tracks = $cd->tracks;
> $tracks = $cd->songs;
This is the point where you should start considering an intermediate
layer between DBIC and your application. When designing new
applications it's recommendable that you stay away from methods that
imply knowledge of your store architecture (such as create, update,
search and insert).
--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://blog.edencardim.com/ http://www.shadowcat.co.uk/servers/
More information about the DBIx-Class
mailing list