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

Matt S Trout <dbix-class-uY5y5/[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
Marc Elser wrote:
> Hi everybody,
> 
> 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.

That's silly.

my @pri = $obj->primary_columns;

should work - or alternatively you could look at backporting the way 
DBIx::Class does it, which notices the field hasn't changed and doesn't bother 
marking it dirty.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
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.