Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony sorted model with having request
    primarykey
    data
    text
    <p>I have two models : Operation and OperationHistory</p> <pre><code>Operation: columns: startdate: { type: timestamp, notnull: true } enddate: { type: timestamp, notnull: true } year: { type: integer, notnull: true } abscomment: { type: string(500) } person_id: { type: integer, notnull: true } operationtype_id: { type: integer, notnull: true } relations: Person: { onDelete: CASCADE, local: person_id, foreign: id, foreignAlias: Operations} OperationType: { onDelete: CASCADE, local: absencetype_id, foreign: id, foreignAlias: Operations } OperationHistory: columns: oh_comment: { type: string(500), notnull: true } oh_date: { type: timestamp, notnull: true } status_id: { type: integer, notnull: true } operation_id: { type: integer, notnull: true } updater: { type: integer, notnull: true } indexes: date: fields: ohdate: sorting: DESC relations: Operation: { onDelete: CASCADE, local: operation_id, foreign: id, foreignAlias: OperationsHistory } Person: { onDelete: CASCADE, local: updater, foreign: id, foreignAlias: OperationsHistory } OperationStatus: { onDelete: CASCADE, local: status_id, foreign: id, foreignAlias: OperationsHistory } </code></pre> <p>In order to get all Operation by Person, I use an index on OperationHistory. So if I need all the person's operation with a specific status:</p> <pre><code>public function getOperations($person, $status){ $q = $this-&gt;createQuery('o') -&gt;leftJoin('o.OperationsHistory oh') -&gt;leftJoin('p.Person p') -&gt;groupBy('ah.absence_id') -&gt;having('ah.status_id = ?', $status); return $q-&gt;execute(); } </code></pre> <p>Thanks to the index on ohdate, I assume with the groupBy, I only get the last OperationHistory about a specific Operation. Without the having clause, It's good, but I only want Operations with a specific Status. But if I set this having clause, I get nothing at all.</p> <p>In fact, I need to translate this sql request :</p> <pre><code>SELECT * FROM operation o LEFT JOIN ( SELECT * FROM operation_history ORDER BY ohdate DESC ) oh ON o.id = oh.absence_id LEFT JOIN person p ON p.id = o.person_id WHERE p.id = 1 GROUP BY oh.operation_id HAVING oh.status_id = 1 </code></pre> <p>sorry for my bad english and I hope these informations will be usefull to help me.</p> <p>Thank u !</p>
    singulars
    1. This table or related slice is empty.
    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.
    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