[rt-devel] DBIx::Searchbuilder woes

Michael Grubb mgrubb at fifthvision.net
Thu Aug 22 14:28:08 EDT 2002

You would add the ENTRYAGGREGATOR to the second call of a Limit* routine.

The way it works, is the limit calls set up a where clause for the select
query represented by the DBIx::SearchBuilder class.
With each call to Limit it adds a constraint that is by default ANDed with
 the previous constraints.  If you want a constraint to be ORed instead of
 ANDed then you would add the ENTRYAGGREGATOR='OR' to the limit call that
 would appear after the OR in the SQL.
So in your example the query would look something like this:

SELECT * FROM Tickets WHERE Requestor = $session{'CurrentUser'}->EmailAddress
AND CC = $session{'CurrentUser'}->EmailAddress;

(With the variable references expanded of course, and the Table name and
selected fields are actually different than what is sent to the database
backend because DBIx::SearchBuilder does some magical massaging of the names
of tables and fields (or at least tables) by way of aliases.

So if you wanted to replace the AND above with OR you would change your
LimitCC call to
$MyTickets->LimitCc(VALUE => $session{'CurrentUser'}->EmailAddress,

Just remember that Limit method calls really just append 'AND|OR Field =
VALUE' to the WHERE clause of a query.  and of course you can do things such
as Like by setting the OPERATOR key in the parameter hash to 'LIKE'

You are very right about the documentation of DBIx::SearchBuilder though.
I built an application unrelated to RT on top of it.  I think it is a great
library, but it is a bear to learn.  The way I figured it out was by
examining nearly all of the RT modules and examing the DBIx::SearchBuilder
code indepth, however this is not so bad because Jesse codes better than most
perl programmers.

On Thursday 22 August 2002 05:51 am, Robie Basak wrote:
> Hi,
> I'm trying to use DBIx::SearchBuilder, but failing miserably.
> I'm trying to change the requestor-mode interface so that the open and
> closed ticket pages contain a list of everything where the logged-in
> user is either the requestor _or_ the Cc (permissions have been set
> appropriately).
> In WebRT/html/SelfService/Elements/MyRequests, there is:
> $MyTickets->LimitRequestor(VALUE =>
> $session{'CurrentUser'}->EmailAddress);
> so I added
> $MyTickets->LimitCc(VALUE => $session{'CurrentUser'}->EmailAddress);
> This resulted in no records. Presumably it's doing an AND instead of an
> OR.
> Searching the archives and googling randomly didn't seem to help;
> DBIx::SearchBuilder->Limit isn't really documented properly anywhere;
> the manpage doesn't really explain it, and seems to be really outdated.
> I dug around in the code, and tried an ENTRYAGGREGATOR = 'OR', but what
> I don't understand is that it appears that this is supposed to be the
> default anyway.
> How does ENTRYAGGREGATOR work? I don't understand if it's supposed to
> be added to the first Limit call, the second or both. Is it prefix or
> postfix or something else?
> If someone would explain it I'll happily document what I learnt.
> Cheers,
> Robie.
> _______________________________________________
> rt-devel mailing list
> rt-devel at lists.fsck.com
> http://lists.fsck.com/mailman/listinfo/rt-devel

More information about the Rt-devel mailing list