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

"Peter Speltz" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
On 6/13/06, Marc Elser <[email protected]> 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.

-- 
pjs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.