[Rt-devel] [Searchbuilder] how to access fields from both joined tables in a SearchBuilder object

Kevin Falcone falcone at bestpractical.com
Wed Oct 6 12:19:36 EDT 2010


On Mon, Oct 04, 2010 at 05:33:57PM +0200, Mathieu Lafage wrote:
> Dear all,
> 
> I believe I reached the correct place for a question about
> DBIx::SearchBuilder,
> otherwise please forgive my noise.
> 
> I read the module documentation, the "RT Essential" book, I crawled this ML
> archives, as well as google, and I gave a look at RT source code,
> however I admit
> I did not dive very deep in Tickets.pm generic query code, but I did
> not find
> a clear answer to this question :
> 
>   Can you access fields from both joined tables in your result set
>   when you join two tables with Searchbuilder ?

Unfortunately, you can't.  If views perform well in your database
choice, that may be a solution.  This is why you will often see RT
code that loops and goes and fetches more data.

-kevin

> From my understanding and tests, this is not possible, or not obviously.
> You SearchBuilder-derived class is connected to one table (through
> $self->Table('mytable'); ) and you thus return records of a
> SearchBuilder::Record
> type linked to this base table.
> 
> Should I :
> - forget using SearchBuilder for this purpose, it can not do it. period,
> - create a proper view in my database, and create a SearchBuilder
> object accordingly,
>   thus working around the SearchBuilder "limitation" described here,
> - go back to "Modeling 101" and learn why what I want to do is bad.
> Please, teach me.
> - use the splendid solution you will certainly describe here. :)
> 
> NB: I thought about the two following solutions, but I want to know
> if there is
> a better (more general) way :
> 1) I may define my tables so I don't need to perform a Join in the
> first place to
> get related informations, but I'm afraid normalization might suffer
> outrages here.
> 2) Alternately, I may access my two tables separately (with a
> SearchBuilder object
> each) and "join" in the perl code, but I'm afraid I will call this a kludge.
> 
> Best regards,
>   Mathieu
> _______________________________________________
> List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-devel/attachments/20101006/3905d291/attachment.pgp>


More information about the rt-devel mailing list