johnnywang has asked for the wisdom of the Perl Monks concerning the following question:
use the passed-in parameters to either update or create a new record. In my situation, my %params are used by several classes, therefore it contains more keys than the columns of any individual class. When I passed it in the above two methods, I get the "no such column" error. My question is what is the best way to allow this. I did the following (I used a different method name), which constructs another param with keys coming from the columns(). I didn't like this since it relies on knowing something about how the parameters get translated to column names, and it might not work well when access/mutator names get changed. Is there a better way? Thanks.set(%params); create(\%params);
sub set_all{ my($self, %params) = @_; my %p =(); # construct a new param foreach my $c ($self->columns()){ my $normalize = lc $c; # seems internally always lower case $p{$normlize} = $params{$normalize} if $params{$normalize}; } $self->set(%p); # call the original set }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to tell Class::DBI to ignore some parameters
by mpeters (Chaplain) on Feb 25, 2005 at 21:50 UTC |