Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Re: Class::DBI find_or_create method inserts record but $obj->id is undef

by runrig (Abbot)
on Jan 24, 2004 at 00:24 UTC ( [id://323749]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Class::DBI find_or_create method inserts record but $obj->id is undef
in thread Class::DBI find_or_create method inserts record but $obj->id is undef

Read the CGI docs:
$q->delete('class_id')
  • Comment on Re: Re: Re: Class::DBI find_or_create method inserts record but $obj->id is undef
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: Class::DBI find_or_create method inserts record but $obj->id is undef
by jerrygarciuh (Curate) on Jan 24, 2004 at 00:37 UTC
    Mea culpa. Thanks for the reminder I have been away from Perl for a good while.

    Unfortunately the Class::DBI update() method does not work unless the $obj has an id defined and part of the problem here is that the insert id isn't in $obj unless find_or_create gets an explicit undef or an explicit $id.
    TIA
    jg

    _____________________________________________________
    "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
      That's why I said you should delete the value AFTER the call to find_or_create. Alternatively, you could replace your loop with this:
      foreach my $field (grep { $_ ne 'id' } $q->param) {
        Perrin,
        I appreciate your replying but the deletion is being done after the call to find_or_create. For whatever reason when CGI is packaging up the hidden field in the form that sets id='' it does it in a way that Class::DBI sees as other than undef. Deleting the $q->param does not solve this. However, having Template-Toolkit conditionally print the hidden field based on whether id is deined does solve the problem. No param named id unless it is defined. Still, it is odd to me that Class::DBI would have this behavior. Thank you for your attention to my dilemma!
        Peas and hominy,
        jg
        _____________________________________________________
        "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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found