[CDBI] Re: delete on table with multiple pks

Jim Salladin jsalladin at gmail.com
Wed Nov 30 05:18:52 GMT 2005


On 11/26/05, William Ross <will at spanner.org> wrote:
> the active ingredient here is:
>
>    eval { $self->sql_DeleteMe->execute($self->id) };
>
> (cdbi line 705)
>
> the call to $self->id should return a list of two key values suitable
> for binding to the delete statement, but it isn't: you're only
> getting one. I don't know why. What do you get when you call $self-
>  >id directly?
>    eval { $self->sql_DeleteMe->execute($self->id) };
>
> (cdbi line 705)
>
> the call to $self->id should return a list of two key values suitable
> for binding to the delete statement, but it isn't: you're only
> getting one. I don't know why. What do you get when you call $self-
>  >id directly?

Thanks. This got me on the right path. The issue is that there is a
conflict with one of the column names, it is "id". So when doing
somehting to the effect of $self->id  I was getting:
Caught exception "Can't call id() as a class method "

I tried changing the name of the column to tablename_id and then the
error went away obviously.

This is really annoying though. I have had to do several things with
the basic database data mode lto get around this issue while others
parts I cannot change as there is a really old table with a column
name of id. I would guess there are lots of column names out there in
the world with the name "id", whether it is good practice or not. Not
sure why the __PACKAGE__->id has to clobber any potential table object
methods. This may be an old discussion in Class::DBI but it just seems
very impractical. Is there a way to alias column names to get around
this?

Jim.




More information about the ClassDBI mailing list