[CDBI] cannot use get method after updating fields in object
melser at gmx.ch
Tue Jun 13 22:05:15 BST 2006
I'm running into a problem I don't understand because the documentation
says this should work, but I can't get it to work, I'm using
Class::DBI-3.0.14. Would be great if anybody could tell me what I'm
doing wrong. Here's the problem:
First I retrieve a model::Depot object and store it in $obj (where
model::Depot is a subclass of Class::DBI). Then I update all fields in
the $obj object with new values which unloads these fields from the
object to make sure they're consistent with the database (says the CPAN
documentation). I can confirm this by doing a Data::Dumper on my $obj
object it shows a blessed empty hash from the class model::Depot.
Here comes the problem: the CPAN documentation states the if the fields
are needed again (which were unloaded by updating them) they will be
simple fetched from the database. But somehow this doesn't seem to work.
When I do a $obj->get('name') which is a valid field, I get 'undef'
instead of the real value. Is this because the primary key has been
unloaded too, or what's the problem here?
If so is there a method in Class-DBI which I can ask which column is the
primary key because the method which updates the fields is inherited and
does not know which class it's actually working on. If I can find out
which is the primary key then I could simply skip it in this method
which would leave the primary key in the $obj.
Would be great to hear what I can to solve the problem, because after
updating the fields I must process some values, but if I only get
'undef' I can't process anything.
Any help is greatly appreciated cause I'm really stuck here.
More information about the ClassDBI