Note that there are some explanatory texts on larger screens.

plurals
  1. PODQL complex query in Symfony2 application
    text
    copied!<p>I have this situation in my model:</p> <p>Product belongs to a Category. TransactionDetail has Product, price and quantity. Transaction has TransactionDetails and date. Shop has Transactions. Group has Shops.</p> <p>They are Doctrine entities and they are properly related. (I don't paste the classes, it would be too long).</p> <p>Thing is I need to query the model to obtain the total products sold (SUM TransactionDetail.quantity) and the total money (SUM TransactionDetail.quantity * TransactionDetail.prize), grouped by Product, From the Transactions of Products of a certain Category in a certain Group that happened in a range of dates.</p> <p>Ok, I did this in plain SQL and it would be something like</p> <pre><code>select TransactionDetail.product, SUM(TransactionDetail.quantity) as quantity, SUM(TransactionDetail.quantity*TransactionDetail.prize) as euros from TransactionDetail left join Transaction on TransactionDetail.transaction = Transaction.id left join Product on TransactionDetail.product = Product.id left join Group on Transaction.shop = Group.shop where Product.category = :paramCategoryId and Group.id = :paramGroupId group by TransactionDetail.product </code></pre> <p>The thing is I have NO IDEA about how do I put this in a DQL query (as plain SQL is not recommended, and I really would like to have a better understanding of the power of DQL).</p> <p>Can you guys help me?</p> <p>Thanks in advance.</p> <p>=============================================================================<br /> EDIT:</p> <p>State of the art query:</p> <pre><code>SELECT d, p, SUM(d.quantity) as quantity, SUM(d.quantity*d.prize) as euros FROM TransactionDetail d LEFT JOIN d.transaction t LEFT JOIN d.product p LEFT JOIN t.shop s LEFT JOIN s.groups g ON s.id MEMBER OF g.shops WHERE p.category = :category AND g.id = :group AND t.date &gt; :from AND t.date &lt; :to GROUP BY p </code></pre> <p>Problems: s.groups is a collection, and so is g.shops. I don't know how in the world this query must be done.</p>
 

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