Welcome, Guest
Username: Password: Remember me

TOPIC: GROUP BY missing, messing up queries

GROUP BY missing, messing up queries 01 Mar 2015 12:14 #12871

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
The follow is an SQL statement generated by my Cook Component
SELECT a.id,a.checked_out,a.created_by,a.published,a.category,a.logo,a.name,a.summary,_category_.category AS `_category_category`,_checked_out_.name AS `_checked_out_name`,COUNT(_deals_.id) AS `_deals_count`

  FROM vl9d3_comp_venues AS a

  LEFT JOIN `vl9d3_comp_venuecategories` AS _category_ 
  ON _category_.id = a.category

  LEFT JOIN `vl9d3_users` AS _checked_out_ 
  ON _checked_out_.id = a.checked_out

  LEFT JOIN `vl9d3_comp_deals` AS _deals_ 
  ON _deals_.pin = a.id

  WHERE (0 OR 1)

  ORDER BY a.category,a.ordering asc 
  LIMIT 0, 20

However whereas this returns only 1 result, it should be returning every single venue (4 in total)

The problem is that the SQL should be
SELECT a.id,a.checked_out,a.created_by,a.published,a.category,a.logo,a.name,a.summary,_category_.category AS `_category_category`,_checked_out_.name AS `_checked_out_name`,COUNT(_deals_.id) AS `_deals_count`

  FROM vl9d3_comp_venues AS a

  LEFT JOIN `vl9d3_comp_venuecategories` AS _category_ 
  ON _category_.id = a.category

  LEFT JOIN `vl9d3_users` AS _checked_out_ 
  ON _checked_out_.id = a.checked_out

  LEFT JOIN `vl9d3_comp_deals` AS _deals_ 
  ON _deals_.pin = a.id

  WHERE (0 OR 1)

  GROUP BY a.id

  ORDER BY a.category,a.ordering asc 
  LIMIT 0, 20

However the groupBy class has been depreciated with no replacement. I have tried readding it with no success and various messing with the prepareQuery to try and inject it with, again, no success

How can I insert this essential GROUP BY statement with majorly hacking the code and why was it removed when it is sometimes essenial?
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
Last Edit: 01 Mar 2015 12:14 by MorganL.
The administrator has disabled public write access.

GROUP BY missing, messing up queries 13 May 2015 12:25 #12979

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
I have made a topic about this:

www.j-cook.pro/index.php/forum/new-ticke...not-working-properly

In the next version it should be fixed according to adim, bu if you want to fix it now, for your model and copy paste the prepareQuery function in it.

Then where you find
		//GROUP ORDER : Prioritary order for groups in lists
		foreach($this->getState('query.groupOrder', array()) as $groupOrder)
			$query->order($groupOrder)

replace $query->order($groupOrder) with $query->group($groupOrder)
That will probably fix your problem
Last Edit: 13 May 2015 12:29 by Romkabouter.
The administrator has disabled public write access.

GROUP BY missing, messing up queries 29 May 2015 09:07 #13193

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Since 2.7, you can use :
$model->addGroupBy()


Note: addGroupOrder() is used the group items together in the lists, but is not an agregating function. It is not the real SQL GROUPBY statement. Only a prioritary order.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: MorganL

GROUP BY missing, messing up queries 29 May 2015 09:30 #13194

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
Working fine now, I had tried to write a class fork to fix it, and this broke the fix in 2.7. As soon as I removed the override it works fine
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.
Time to create page: 0.068 seconds

Get Started