Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Class::DBI, reblessing and primary key names

by glwtta (Hermit)
on Jan 09, 2005 at 23:48 UTC ( [id://420771]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://420771]
Approved by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found