[CDBI] Re: Changing Your Column Accessor Method Names

Derek Basch dbasch at yahoo.com
Tue Jun 20 00:37:13 BST 2006

dbasch wrote:
> Everyone,

> I am gettting this error message:

> Column 'id' in Database::Tql::Custdb clashes with built-in method at
> class_dbi_test.pl line 26

> and can't quite figure out how to fix it. I see there are several
> solutions listed in the wiki:

> http://wiki.class-dbi.com/wiki/Overriding_autogenerated_accessors

> But they don't seem to do anything. Am I doing this (below) all wrong?

After a few more hours of digging I found that the name of the method
had changed to 'accessor_name_for' instead of 'accessor_name'. I had
been reading some older documentation. Note this alternative method of
creating an explicit accessor when declaring your columns:

        my $meta_col = Class::DBI::Column->new(meta_info => {
                accessor => 'metadata',

  __PACKAGE__->columns(All => qw/id name/, $meta_col);

However, it only works if 'id' is declared as your primary column. If
'id' is not declared as your primary column you will need to use the
'accessor_name_for' function. Example below:

use strict;
use warnings;

package OkbridgeDatabase::Tql::Custdb;
use base 'OkbridgeDatabase::Tql::DBI';

# Columns named 'id' conflict with the DBI function named 'id'
# Explicitely rename the column accessor
sub accessor_name_for {
  my ($class, $column) = @_;
  return "user_id" if $column eq "id";
  return $column;


OkbridgeDatabase::Tql::Custdb->columns(Primary => qw/people_id/);
OkbridgeDatabase::Tql::Custdb->columns(Essential => qw/user id fullname
email phone contact ncbo address1 address2 address3/);
OkbridgeDatabase::Tql::Custdb->columns(Other => qw/comments1 comments2

I hope that helps someone someday :)

Derek Basch 

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the ClassDBI mailing list