Note that there are some explanatory texts on larger screens.

plurals
  1. POGet aggregated column from query with multiple joins to single table
    primarykey
    data
    text
    <p>I'm struggling with retreiving data in propel 1.6.7.</p> <p>Here's the sample of query I want to achieve:</p> <pre><code>select count(1) as amount, p1.local_id FROM panel_data pd JOIN panel_data_has_code pp1 on (pd.panel_data_id = pp1.panel_data_id) JOIN panel_code p1 on (pp1.panel_code_id = p1.panel_code_id AND p1.type='equipment' AND model_id = 'my_model_id') JOIN panel_data_has_code pp2 on (pd.panel_data_id = pp2.panel_data_id) JOIN panel_code p2 on (pp2.panel_code_id = p2.panel_code_id AND p2.type='model' AND p2.local_id='my_local_id') GROUP BY p1.local_id </code></pre> <p>However whenever I try to construct proper criteria in Propel ORM, I'm having an issue - apparently propel always translate join alias to table name, whenever I try to use add join condition or use alias in select method. I've replaced multiple join condition with simple <code>filterBy</code> method (I always use inner joins, so effect will be the same), but I'm still having issue with retreiving groupped column (p1.local_id).</p> <p>Here's the code I work with atm:</p> <pre><code>PanelDataQuery::create() -&gt;select(array( 'p1.localId')) -&gt;withColumn('count(1)', 'amount') -&gt;usePanelDataHasCodeQuery('pp1')-&gt;usePanelCodeQuery('p1')-&gt;groupByLocalId()-&gt;filterByType($type)-&gt;endUse()-&gt;endUse() -&gt;usePanelDataHasCodeQuery('pp2')-&gt;usePanelCodeQuery('p2')-&gt;filterByType('model')-&gt;filterByLocalId($model)-&gt;endUse()-&gt;endUse() -&gt;find(); </code></pre> <p>Above statement returns an error:</p> <blockquote> <p>Unable to execute SELECT statement [SELECT count(1) AS amount, panel_code.LOCAL_ID AS \"p1.localId\" FROM panel_data INNER JOIN panel_data_has_code pp1 ON (panel_data.PANEL_DATA_ID=pp1.PANEL_DATA_ID) INNER JOIN panel_code p1 ON (pp1.PANEL_CODE_ID=p1.PANEL_CODE_ID) INNER JOIN panel_data_has_code pp2 ON (panel_data.PANEL_DATA_ID=pp2.PANEL_DATA_ID) INNER JOIN panel_code p2 ON (pp2.PANEL_CODE_ID=p2.PANEL_CODE_ID) WHERE p1.TYPE=:p1 AND p2.TYPE=:p2 AND p2.LOCAL_ID=:p3 GROUP BY p1.LOCAL_ID] [wrapped: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]The multi-part identifier \"panel_code.LOCAL_ID\" could not be bound.]</p> </blockquote> <p>Obviously, select clause causes the problem. Any ideas how to force propel to use table alias instead of translating it to table name?</p> <p>Thank you in advance for any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload