[Dbix-class] Accessors for joined table columns

Matt S Trout dbix-class at trout.me.uk
Thu May 29 11:39:16 BST 2008


On Sun, May 18, 2008 at 01:19:06PM +0100, ben at drn.org wrote:
> Hi,
> 
> I've been unsuccessful in creating an accessor alias for a column in a
> many-to-one joined table. Here's my simplified schema defs:
> 
> package Track;
> 
> use base qw/DBIx::Class/;
> 
> __PACKAGE__->load_components(qw/UUIDColumns PK::Auto UTF8Columns Core/);
> __PACKAGE__->table('track');
> __PACKAGE__->resultset_class('DBIx::Class::ResultSet::Data::Pageset');
> __PACKAGE__->add_columns(qw/id name/);
> __PACKAGE__->set_primary_key(qw/id/);
> __PACKAGE__->uuid_columns(qw/id/);
> __PACKAGE__->uuid_class('::Data::UUID');
> __PACKAGE__->utf8_columns(qw/name/);
> 
> __PACKAGE__->has_many(trackdescriptions => 'TrackDescription', 'track_id');

> __PACKAGE__->add_columns('trackdescriptions.description' => { accessor =>
> 'description' });

This line is complete bollocks. add_columns if for columns on -your- table.

Also, if the rel is really a has_many, then you can't add an accessor anyway
since there could be more than one. 

If it was a belongs_to, then you could just write

sub description { shift->track_description->description }

or pass the 'proxy' relationship attribute to your belongs_to definition.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list