[CDBI] Having a column named 'id' as part of a multi-column primary key

[prev] [thread] [next] [Date index for 2005/08/10]

From: Scotty Allen
Subject: [CDBI] Having a column named 'id' as part of a multi-column primary key
Date: 04:05 on 10 Aug 2005
Hi all,

I've been working with an existing table (existing meaning pre-using-
cdbi), which has a two column primary key.  One of the columns is named
'id'.  When I try to set this up using:

__PACKAGE__->columns(Primary => qw/id program/);

I get an error, stating "Column 'id' in My::DBI::ProgramCounty clashes
with built-in method".  This somewhat makes sense, as CDBI has a builtin
called id(), which returns the primary key(s).

However, it looks like there was an attempt to fix this in _make_method,
for tables which had a single column 'id', as long as it was the primary
key:

$class->_carp("Column '$name' in $class clashes with built-in method")
    if Class::DBI->can($name)
    and not($name eq "id" and join(" ", $class->primary_columns) eq "id");

Tony also states this is the case in
http://www.spanner.org/lists/cdbi/2004/06/18/e83e8291.html

However, it doesn't work if, as in my case, id is a member of a multi-
column primary key.

Is there any reason the above code shouldn't read:

$class->_carp("Column '$name' in $class clashes with built-in method")
    if Class::DBI->can($name)
    and not($name eq "id" and grep {$_ eq "id"} $class->primary_columns);

-Scotty


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] Having a column named 'id' as part of a multi-column primary key
Scotty Allen 04:05 on 10 Aug 2005

Generated at 13:17 on 19 Aug 2005 by mariachi v0.52