[rt-users] Error in "RT Essentials" book.

Ruslan Zakirov ruslan.zakirov at gmail.com
Wed Nov 2 15:09:07 EST 2005


On 11/2/05, Joby Walker <joby at u.washington.edu> wrote:
> It is an error but the two statements in the book are equivalent:
>
> pg 88
>
> if ($Transaction->CreatorObj->id != $RT::Nobody->id){}
>
> pg 89
>
> unless ($Transaction->CreatorObj->id == $RT::Nobody->id){}

"unless(...)" in perl is equiv to "if(not(...))" and "not($val1 ==
$val2)" is equal to
"($val1 != $val2)".

You can also use next equivalent that doesn't require loading of the
new User object:
unless ($Transaction->Creator == $RT::Nobody->id){}

General rule is next:
if object's field is id of the record in other table(fields like
Creator, LastUpdateBy, Ticket, Transaction, GroupId, MemberId...) then
in most cases class(in the example RT::Transaction) has method named
FieldObj that creates new referenced object and load data by id.
Pseudo code for CreatorObj method looks like:

my $obj = new RT::User;
$obj->Load( $self->Creator );
return $obj;


Book has errata page on the Oreily site, please fill info about error there.

>
>
> Different ways to check for the same negative; "if this is not true" vs.
> "unless this is true".
>
> Joby Walker
> ITI SSG, University of Washington
>
>
> Shaun T. Erickson wrote:
> > On page 88, it describes how to modify the autoreply template to give
> > the user a password if they don't already have one. In the modified
> > template listed, the first part of the new code starts off as:
> >
> > if ( $Transaction->CreatorObj->id != $RT::Nobody->id
> >
> > but on page 89, where they discuss that new code, they replaced the 'if'
> > with 'unless'.
> >
> > Which is it?
> >
> > --
> >         -ste
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> >
> > Be sure to check out the RT Wiki at http://wiki.bestpractical.com
> >
> > Buy your copy of our new book, RT Essentials, today!
> >
> > Download a free sample chapter from http://rtbook.bestpractical.com
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Be sure to check out the RT Wiki at http://wiki.bestpractical.com
>
> Buy your copy of our new book, RT Essentials, today!
>
> Download a free sample chapter from http://rtbook.bestpractical.com
>


--
Best regards, Ruslan.



More information about the rt-users mailing list