Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
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

Please Log in or Create an account to join the conversation.

Last edit: by MorganL.

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

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

Please Log in or Create an account to join the conversation.

Last edit: by Romkabouter.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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 following user(s) said Thank You: MorganL

Please Log in or Create an account to join the conversation.

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

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
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

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.059 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started