good chemistry is complicated,
and a little bit messy -LW
Class::DBI find_or_create method inserts record but $obj->id is undefby jerrygarciuh (Curate)
|on Jan 23, 2004 at 23:46 UTC||Need Help??|
jerrygarciuh has asked for the
wisdom of the Perl Monks concerning the following question:
I am making the administrative methods for a largish educational project using Class::DBI, Template-Toolkit, and CGI::Application. I have had three occasions now when attempting to use the sequence
If I set $id explicitly to undef then the Class::DBI record object $obj has the new record's row in $obj->id after find_or_create(). Thing is I need to check @_ and $q->param() for $id. Now, if either @_ or $q->param() has a value for $id, the the record gets appropriately put into $obj, altered in my foreach and then updated by $obj->update;
The bug shows up when $q->param and @_ do not have a value for $id. Class::DBI's find_or_create() inserts the new row in the db but $obj->id is undef, and consequently the $obj->update does no good.So my question to you is how best to do this. Should I make a test for the contents of $id and set it explicitly to undef if it fails? What is a Good way to do this?
"The man who grasps principles can successfully select his own methods.
The man who tries methods, ignoring principles, is sure to have trouble.
~ Ralph Waldo Emerson