find_or_create method problem with TEMP columns
[prev]
[thread]
[next]
[Date index for 2004/12/28]
I ran into a problem with find_or_create when there
were temp columns. It would complain that it couldn't
select the temp column from the table. I fixed the
problem by adding this to my base class I declared.
sub find_or_create {
my $class = shift;
my $hash = ref $_[0] eq "HASH" ? shift: {@_};
my @temp_col = $class->columns("TEMP");
my %temp = ();
map { $_ = $_->name } @temp_col;
map {
my $key = $_;
map {
if ($key eq $_)
{
$temp{$key} = $hash->{$key};
delete $hash->{$key};
}
} @temp_col;
} keys %$hash;
my ($exists) = $class->search($hash);
map { $hash->{$_} = $temp{$_}; } keys %temp;
my $object = defined($exists) ? $exists :
$class->create($hash);
return $object;
}
I'm sure there is a much better way to do it, but it
fixed the issue I was having. Any ideas on a better
way to do this?
|
find_or_create method problem with TEMP columns
Brian Doig 23:12 on 28 Dec 2004
|