Re: oracle woes
[prev]
[thread]
[next]
[Date index for 2004/07/14]
On 13 Jul 2004 20:48:07 -0700, Randal L. Schwartz <merlyn@xxxxxxxxxx.xxx>
wrote:
> OK, I'm stumped, after staring at ->trace(3) traces for an hour or so.
>
> My::DB::List->columns(Primary => 'id');
> My::DB::Person->columns(Primary => 'id');
> My::DB::Manager->columns(Primary => qw(list person));
> My::DB::Manager->has_a(list => My::DB::List);
> My::DB::Manager->has_a(person => My::DB::Person);
> My::DB::Manager->columns(Other => qw(is_owner));
What's your CDBI version? Following lines are valid for 0.95.
CDBI has difficulties to handle has_a relations when one of
the columns in a multi column PK is a ref to another object.
try to overload id() function in your root class with following...
########################################
#
# id() return LIST
#
# Overloading Class::DBI::id() to fix a problem with unresolved
# hash references when elements of primary key are objects.
# Functions like update() try to bind this refs direct to
# DBI calls and blow up. :-(
sub id
{
my $self = shift();
my $class = ref($self)
or return $self->_croak("Can't call id() as a class method");
# we don't use get() here because all objects should have
# exisitng values for PK columns, or else loop endlessly
my @pk_values = $self->_attrs($self->primary_columns);
# resolve all refs into usefull key values
@pk_values = map(ref($_) && $_->isa('Class::DBI') ?
$_->id() : $_, @pk_values);
return @pk_values if wantarray;
if (@pk_values > 1)
{
$self->_croak("id called in scalar context for class with multiple
primary key columns");
}
return $pk_values[0];
}
good luck
- adam
--
-----------------------------------------------------------------------
Adam Przygienda
Computer Science Engineer SEC
SWISSCOM Enterprise Solutions AG
IP-Plus Internet services http://www.ip-plus.net
mailto: adam@xxxxxxx.xxx
phone: +41 (0)1 274 65 62 mobile: +41 (0)79 777 41 17
-----------------------------------------------------------------------
|
oracle woes
merlyn (Randal L. Schwartz) 03:48 on 14 Jul 2004
|
|
|
Re: oracle woes
Adam Przygienda 08:44 on 14 Jul 2004
|