glwtta has asked for the wisdom of the Perl Monks concerning the following question:

Good Evening,

(I just asked this on the C:DBI list as well; those of who see both - sorry about that :) )

Seems I've just exceeded my level of knowledge of Class::DBI internals: I'm trying to rebless a retrieved C:DBI object into a subclass of its original class that adds some (non-Essential) columns, removes some columns (no problems with those two) and changes the name of the primary key (that one's a problem).

I don't want to change the value of the primary key (a big no-no from what I understand), just the name. Most importantly the reblessing procedure should not hit the database at all (until the object goes to lazily fetch the new column group defined in the subclass).

Is there a way to rename the column name, its accessor and mutator? I don't care if the old value is still there, as long as it doesn't try to fetch the old column on the next database trip.

Another approach I am thinking of is to ->construct() the new object I want from scratch, but this requires overloading the constructors and I'd much rather do the reblessing from a 'select' trigger (seems like it'd be faster, too).

Any suggestions?

  • Comment on Class::DBI, reblessing and primary key names

Replies are listed 'Best First'.
Re: Class::DBI, reblessing and primary key names
by castaway (Parson) on Jan 10, 2005 at 08:45 UTC
    Unless I'm misunderstanding your question, then my suggestion would be to read the manual, especially:
    Changing Your Column Accessor Method Names accessor_name / mutator_name If you want to change the name of your accessors, you need to provide an accessor_name() method, which will convert a column name to a method name. e.g: if your local naming convention was to prepend the word 'customer' to each column in the 'customer' table, so that you had the columns 'customerid', 'customername' and 'customerage', you would end up with code filled with calls to $customer->customerid, $customer->customername, $customer->customerage etc. By creating an accessor_name method like: sub accessor_name { my ($class, $column) = @_; $column =~ s/^customer//; return $column; } Your methods would now be the simpler $customer->id, $cusĀ­ tomer->name and $customer->age etc.
    (Direct copy&paste from the perldoc)

    Is that what you were looking for?

    C.