[Dbix-class] Fixing my relationships to get working queries

John Stoffel john at stoffel.org
Mon Jan 19 18:36:35 GMT 2015


>>>>> "Peter" == Peter Rabbitson <rabbit+dbic at rabbit.us> writes:

Peter> The question as you wrote it is good, I just need to clarify some extra 
Peter> things before I answer it:

Peter> On 01/19/2015 07:23 PM, John Stoffel wrote:
>> 
>> 
>> > ../bin/dbic-test2.pl carpenter
>> SELECT me.name_id, me.full_name, me.last_name, me.first_name, me.comments, account.account_id, account.account_number, account.boxfolder_id, account.name_id, account.url, account.comments, account.volume, account.box, account.folder, account.range FROM (SELECT me.name_id, me.full_name, me.last_name, me.first_name, me.comments FROM names me WHERE ( full_name REGEXP ? ) ORDER BY full_name ASC LIMIT ?) me LEFT JOIN account account ON account.name_id = me.name_id WHERE ( full_name REGEXP ? ) ORDER BY full_name ASC: '[[:<:]]carpenter[[:>:]]', '10', '[[:<:]]carpenter[[:>:]]'
>> Full Name: Carpenter, John  (7333)
>> account_id=3176 boxfolder_id=423  URL: fol01 V=35  F=fol01  R=
>> account_id=3177 boxfolder_id=423  URL: fol01 V=35  F=fol01  R=
>> account_id=3178 boxfolder_id=423  URL: fol01 V=35  F=fol01  R=
>> Full Name: Carpenter, John Jr.  (7334)
>> account_id=3179 boxfolder_id=106  URL: b08f01 V=16  F=1  R=6003-6128
>> account_id=3180 boxfolder_id=112  URL: b08f07 V=16  F=7  R=6780-6806
>> account_id=3181 boxfolder_id=122  URL: b09f02 V=17  F=2  R=6999-7125
>> account_id=3182 boxfolder_id=122  URL: b09f02 V=17  F=2  R=6999-7125

Peter> You show your script as executing one query (there is only one line 
Peter> above), yet further down you say:

>> And I'm completely confused why there are multiple SELECTs since the
>> whole idea of prefetch was to just pull in the info ahead of time

I'm talking about the multiple SELECT statements all mashed together
into the query above which stars with:  SELECT me.name_id,
me.ful_name....  

Why does it need to use TWO regexp matches in the query?  The one I
did by hand up above seems (ha!!) to be more efficient and certainly
clearer about what I'm trying to do.  And it's much more of what I
would expect from the info provided in:

  http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#JOINS_AND_PREFETCHING


Peter> Um... yes - which one is it? Did yoiu get a single SELECT statement or 
Peter> multiple?

So maybe I should have said "a query with multiple SELECTs" in it,
when only one is needed.  




More information about the DBIx-Class mailing list