Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: Reloading CDBI objects from database elegantly

by EvdB (Deacon)
on May 19, 2005 at 20:29 UTC ( #458776=note: print w/replies, xml ) Need Help??

in reply to Re: Reloading CDBI objects from database elegantly
in thread Reloading CDBI objects from database elegantly

Quite right, as the following code shows:

use strict; use warnings; package Foo; use base 'Class::DBI'; __PACKAGE__->connection( 'dbi:SQLite:dbname=db_file', '', '' ); __PACKAGE__->table('foo_table'); __PACKAGE__->columns( All => qw/id name/ ); # create table foo_table ( id integer primary key, name char(10) ); 1; package main; use Test::More 'no_plan'; # In test suite. my $cdbi_object = Foo->create( { name => 'Foo' } ); # Check CDBI object is as expected. is $cdbi_object->name, 'Foo', "name is correct (Foo)"; # Change the name through web site. ok( Foo->db_Main->do("update foo_table set name = 'Bar'"), "update name to 'Bar'" ); # undef and reload object. ok my $cdbi_id = $cdbi_object->id, "get id"; $cdbi_object = undef; ok $cdbi_object = Foo->retrieve($cdbi_id), "retrieve object"; # Check that the name has changed. is $cdbi_object->name, 'Bar', "name has changed to 'Bar'"; ok( $_->delete, "delete object" ) for Foo->retrieve_all;

Still it would b e nice if this could be done more easily with something like $object->freshen.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://458776]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2020-05-28 20:33 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (166 votes). Check out past polls.