Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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.


Comment on Re^2: Reloading CDBI objects from database elegantly
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2015-07-08 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls