[CDBI] Deep recursion

Dave Howorth dhoworth at mrc-lmb.cam.ac.uk
Wed Aug 8 10:32:53 BST 2007


Michael G Schwern wrote:
> Arshavir Grigorian wrote:
>> Hi,
>>
>> I have a table with a primary key called "id". When I make an insert
>> into that table, then try to get the primary key, I get into deep
>> recursion:
>>
>> __PACKAGE__->table('tab');
>> __PACKAGE__->columns(Primary => 'id');
>> __PACKAGE__->columns(All => qw/id .../);
>>
>> ...
>>
>> my $obj = TAB->insert($href);
>> my $id = $obj->id;
>>
>> And in the logs, I see a lot of:
>>
>>         Class::DBI::_flesh('TAB=HASH(0x9102a08)', 'Primary') called at
>> /usr/local/share/perl/5.8.7/Class/DBI.pm line 844
>>         Class::DBI::get('TAB=HASH(0x9102a08)', 'id') called at
>> /usr/local/share/perl/5.8.7/Class/Accessor.pm line 393
>>         Class::Accessor::__ANON__('TAB=HASH(0x9102a08)') called at
>> /usr/local/share/perl/5.8.7/Class/DBI.pm line 857
> 
> If you name a column accessor "id" it blows over the very important built-in
> method "id".  Granted it would be nice if it warned you about this very common
> mistake.

I'm confused by this. All my tables have a column called 'id', which is
the primary key, and everything works fine. AFAIK, this is a very common
choice for the primary key column name. Simon Cozen's famous beer
example for Maypole uses this style, for example. This seems to be the
same situation as Arshavir has.

Are you saying that there's a problem with naming a column 'id' or is
the problem with explicitly redefining an accessor, or something else?

Cheers, Dave



More information about the ClassDBI mailing list