#6081: Add new field in model->find to handle "having"
----------------------------+-----------------------------------------------
    Reporter:  ebadedude    |         Owner:           
        Type:  Enhancement  |        Status:  new      
    Priority:  Medium       |     Milestone:  1.2.x.x  
   Component:  General      |       Version:  1.2 Final
    Severity:  Normal       |    Resolution:           
    Keywords:               |   Php_version:  n/a      
Cake_version:               |  
----------------------------+-----------------------------------------------
Comment (by ebadedude):

 Further description on the issue. I guess I was a little
 vague:[[BR]][[BR]]

 In Transact SQL HAVING is an SQL function just like WHERE, GROUP BY etc.
 It is used in conjunction with GROUP BY as an SQL criterion.[[BR]][[BR]]

 For a definition "The SQL HAVING clause enables conditions at the
 aggregate level. It is used instead of the WHERE clause when Aggregate
 Functions are used."[[BR]][[BR]]

 The HAVING clause is used to SELECT information based aggregate
 information. For example, one may want to list sales representatives that
 have sales totaling over $10,000.[[BR]][[BR]]


 I will also change my earlier posted SQL statement for better
 clarity:[[BR]]
 Assuming we have the following table...

 {{{
 TABLE: Branches
 branch_id  branch_name  region_id  employee_count
 108        New York     100        10
 110        Boston       100        6
 212        Chicago      200        3
 216        Indianapolis 200        2
 404        San Diego    400        6
 415        San Jose     400        3
 }}}

 Now suppose I want a list of regions with employee count > 5, my SQL will
 look like this

 {{{
 SELECT region_id, SUM(employee_count) AS region_count
 FROM Branches
 GROUP BY region_id
 HAVING SUM(employee_count) > 5
 }}}

 The above SQL will return...

 {{{
 region_id  region_count
 100        16
 400        9
 }}}

 Currently to do this I have to setup my parameter array as such:

 {{{
 $params = array(
       'fields' => array('Model.region_id', 'SUM(Model.employee_count) AS
 region_count'),
       'group' => array('Model.region_id HAVING SUM(Model.employee_count) >
 5')
    );

 $this->Model->find('all', $params);
 }}}

 Although the above works, it is a hack.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/6081#comment:1>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to