[Dbix-class] Automatic accessor creation

Matt S Trout dbix-class at trout.me.uk
Wed Oct 3 20:45:25 GMT 2007


On Fri, Sep 28, 2007 at 03:11:33PM +0400, dreel wrote:
> 
> As I know the query joining two or more tables automatically creates accessors for main table columns  and other can be reached through $rs->get_column('col_name'). 
> I'm using  get_column('col_name') for all columns even for main table columns asn it's working fine.
> The question is why a part of columns get accessors automatially and other must be accessed manualy?

If it's declared with add_columns an accessor is created for it. When you do
a join you should access columns in foreign tables through the relationships.

$cd->artist->name

and similar, rather than trying to force DBIC to bring the artist name in and
doing $cd->get_column('name')

> May be better to make automatic accessor creation for any column returned of defined in query?

If you use DBIC properly you almost never need get_column.

Generating random methods on the fly is inefficient and can cause subtle bugs.

-- 
      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