Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Problems? Is your data what you think it is?
 
PerlMonks  

Template / Class DBI question

by jatill (Beadle)
on Aug 11, 2005 at 15:01 UTC ( [id://483083]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

I have a class DBI object called 'person' that I am passing into a template toolkit template.

So the following would work fine:

I am [% person.name %]
If I write the following statement, though, I am accidentally updating the person object in the database. I get a warning because I am updating the person record without doing a commit:
[% person.name = person.name _ ' PHD' %]
DB::Person DB::Person=HASH(0xe57cb0) destroyed with out saving changes to name at...

Is there a way I can update the person.name variable without updating the database record?

CODE tags added by Arunbear

Replies are listed 'Best First'.
Re: Template / Class DBI question
by cees (Curate) on Aug 11, 2005 at 15:40 UTC

    You need to use a temporary variable if you want to do that.

    [% SET proper_name = person.name _ ' PHD' %]

    Or if you really wanted to, you could probably define a TEMP column in your Class::DBI table, which would allow you to do something like this (untested):

    [% person.proper_name = person.name _ ' PHD' %]

    Either way, I think this type of code really doesn't belong in the template though. Unless you have no other option, you should keep this out of the template to leave your templates as simple as possible.

    If you use the TEMP column trick in Class::DBI then just predefine the proper name in your code somewhere, and then just use [% person.proper_name %] directly in your template.

Re: Template / Class DBI question
by shiza (Hermit) on Aug 11, 2005 at 15:41 UTC
    Yes, I think it only updates the database if you call the update method on an object. Unless you have autoupdate turned on.

    Autoupdating is off by default. See Class::DBI for more info. discard_changes is another method that will be of use to you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://483083]
Approved by Arunbear
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.