in reply to Dynamically change tables for Class::DBI

Well, this is really not supported at all by Class::DBI and is very likely to cause you problems all over the place. I would advise you to make separate classes. However, I can tell you how to fix this specific problem.

Class::DBI keeps track of which objects you have in memory. See the "UNIQUENESS OF OBJECTS IN MEMORY" section of the docs for an explanation. You can either turn off this feature, or just remove the object from memory before trying to fetch it again. Here's an example:

my $foo = FooBar->retrieve(1); print $foo->name(), "\n"; # remove the instance of FooBar with an ID of 1 from memory undef $foo; FooBar->table('Bar'); #switch table my $bar1 = FooBar->retrieve(1);

Replies are listed 'Best First'.
Re^2: Dynamically change tables for Class::DBI
by johnnywang (Priest) on Feb 18, 2005 at 21:45 UTC
    Thanks. In the real situation, I may not have access to $foo, i.e., some other part of the program may have made the query. If I call the FooBar->clear_object_index(), how much a performance hit is that? granted it is ugly.

    Update. further reading of the doc shows that the cache will be cleared if $foo is out of scope. That should be enough for me.

      For more help on this, there is info on the wiki here.