[CDBI] cannot use get method after updating fields in object

Peter Speltz peterspeltz at gmail.com
Tue Jun 13 22:23:47 BST 2006

On 6/13/06, Marc Elser <melser at gmx.ch> wrote:

> 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.

probably good idea to show actual code.

> 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?

all but primay keys are discarded.
try $name = $obj->name;
->id gets pk value
->primary_column[s] gets pk[s] name[s]

> 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.

you can definitely solve it.


More information about the ClassDBI mailing list