[rt-users] Can you help with this minor hack?

Bruce Campbell bruce_campbell at ripe.net
Thu Feb 21 17:02:00 EST 2002


On Thu, 21 Feb 2002, Travis Campbell wrote:

> On Thu, Feb 21, 2002 at 09:05:26PM +0100, Bruce Campbell wrote:
> > At a rough guess, try:
> >
> > % my $requestors = $Ticket->Requestors;
> > % while( my $this_requestor = $requestors->Next ){
> > %     if( defined( $this_requestor->OwnerObj ) ){
> > 	<% $this_requestor->OwnerObj->RealName %>
> > %     }
> > % }
> >
> > Of course, <% $Ticket->Requestors->First->OwnerObj->RealName %> might not
> > work either.  I need caffiene to get to sleep.
>
> Won't this just display the realname of the $Ticket owner?

urm, you're wanting a complicated answer, and I need some sleep.

> Hmm.  No, after testing both, they do appear to return the realname of the
> Requestor.
>
> Why wouldn't $Ticket->Requestors->First->OwnerObj->RealName return the
> same thing as $Ticket->OwnerObj->RealName?
>
> Is it because the former has no OwnerObj assigned to it, causing the
> RT::Watcher->OwnerObj method to load the RT::User object for the first
> watcher returned by First?

I'll try to do a pretty schema.  Note that this is applicable to 2.0.x, so
if you're reading the archives in a year or so, this probably won't help
you.

      Ticket (RT::Ticket)
          |   |
          |  Ticket->OwnerObj()
          |   |
          |   \--> Owner of Ticket (RT::User)
          |              |
          |              \-> RealName()
          |
       Ticket->Requestors()
	  |
	  \---> Requestors of Ticket (RT::Watchers with Type 'Requestor',)
                     |               (Scope 'Ticket' and Value Ticket->id)
                     |
                Ticket->Requestors->Next() (or First() )
                     |
	             \-> Single Requestor (RT::Watcher)
                               |
                            ->OwnerObj()
                               |
                               \-> Owner of Requestor Object (RT::User)
                                         |
                                         \-> RealName()


In both cases, we're querying the RealName() method of an RT::User object.
We've gotten there in different methods.

Ticket->OwnerObj->RealName displays the RealName column of the Owner of
the Ticket, by effectively issuing:

	select Users.RealName \
	From Users, Tickets \
	where Tickets.Owner = Users.id \
	and Tickets.id = 'this.ticket.number';

Ticket->Requestors->First->OwnerObj->RealName displays the RealName column
of the first 'Requestor' of the Ticket, by effectively issuing:

	select Users.RealName \
	from Users, Watchers \
	where Watchers.Type = 'Requestor' \
	and Watchers.Scope = 'Ticket' \
	and Watchers.Value = 'this.ticket.number' \
	and Watchers.Owner = Users.id ;

Its probably easier to understand as:

	Ticket->Requestors() returns a list of Watcher objects which are
	marked as 'Requestor's on this specific ticket.

	->First() returns the first match found.  Calling ->Next()
	repeatedly iterates through the list found.  First should always
	return an object, Next will return undef once it gets to the end
	of the list, so don't use Next() when you just want one, as you'll
	shoot your foot off quite nicely.

	->OwnerObj returns the RT::User whose id matches the value of the
	Owner field of the Watcher object returned by First().

	->RealName is obvious.

To answer your question (several pages up), they're not the same object.
They're the same object type, but markedly different paths to get there.

That explains ticket Owners and ticket Requestors.  I'd appreciate it if
you could do a similar schema to describe human female behaviour (without
using rand()!) ;)

-- 
                             Bruce Campbell                            RIPE
                   Systems/Network Engineer                             NCC
                 www.ripe.net - PGP562C8B1B                      Operations





More information about the rt-users mailing list