[CDBI] cannot use get method after updating fields in object
Matt S Trout
dbix-class at trout.me.uk
Thu Jun 15 15:11:38 BST 2006
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.
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/ +
More information about the ClassDBI