Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] "GroupBy" generator error in Models - prepareQuery

"GroupBy" generator error in Models - prepareQuery 13 May 2013 13:01 #7181

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Hi

The j-cook generator currently writes the following code in the prepareQuery method of each Model. This will result in the ordering of your query by the fields specified in "$groupby" and NOT a grouping.
	//ORDER
	foreach($this->getState('query.groupby', array()) as $groupby)
		$query->order($groupby);


The correct code should look more like the one below.
	//GROUP
	foreach($this->getState('query.groupby', array()) as $groupby)
		$query->group($groupby);

Hope this helps someone coding in this area...

Regards
v
The administrator has disabled public write access.
The following user(s) said Thank You: dieda1821, ewajoom

Re: "GroupBy" generator error in Models - prepareQuery 12 Jun 2013 10:21 #7449

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
I was trying and trying using $query->groupby($groupby);

THANKS A LOT!
The administrator has disabled public write access.

Re: "GroupBy" generator error in Models - prepareQuery 13 Jun 2013 18:54 #7467

  • dyoungers
  • dyoungers's Avatar
  • Offline
  • Premium Member
  • Posts: 123
  • Thank you received: 16
  • Karma: 0
It's my understanding that the generated code for Group By is correct and it is used for a completely different purpose than an SQL Group By (as confusing as that may seem)

When you select Group By in the grid properties (or in a select list property), the state "query.groupby" is used to sort the result data so that each of the result rows can be "grouped" within the grid (or select list.)

or am I missing something here?

Dave
The administrator has disabled public write access.
The following user(s) said Thank You: vlemos

Re: "GroupBy" generator error in Models - prepareQuery 13 Jun 2013 23:18 #7469

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Hello Dave

This is truly interesting information and I was able to find a Feb 12 2013 post which may have informed your understanding. Maybe if I had seen this post before my submission I may have refrained.

The j-cook project is one of the best of its kind and it is nice that we all try to contribute in little ways to make life easy for each other.

In the final analysis, for me, it is about achieving specific results for my managers and clients. Therefore, I hold nothing as sacred; one programmer's feature can be another one's bug. One must decide for one's self if a given feature is useful in a particular context or if it stands in the way of delivering the final product.

I hope these threads can continue to inform j-cook users who may be faced with this interesting dilemma. Feature or bug? :lol:

Thank you for sharing
v
The administrator has disabled public write access.

Re: "GroupBy" generator error in Models - prepareQuery 13 Jun 2013 23:45 #7470

  • dyoungers
  • dyoungers's Avatar
  • Offline
  • Premium Member
  • Posts: 123
  • Thank you received: 16
  • Karma: 0
The j-cook project is indeed one of the best tools I've run across for building Joomla components and the beta version should make things even better!

While I use the group by to organize individual records in the grid (which can then be edited, published, etc.) I certainly understand that in some cases, an aggregated result may be appropriate and that is what is nice in this tool, it allows everyone to customize in a way that fits their needs :)

Dave
The administrator has disabled public write access.

Re: "GroupBy" generator error in Models - prepareQuery 24 Jun 2013 13:28 #7623

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Thank you for your suggestions.

addGroupBy() has been replaced by addGroup()

www.j-cook.net/index.php/docs/versions/77-2-5-3

addGroupBy() is still available, but deprecated.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: vlemos

Re: "GroupBy" generator error in Models - prepareQuery 24 Jun 2013 14:36 #7633

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Thanks for listening:

However, if this is really an ordering function, then its true nature should be reflected in its name. To me, "addGroupOrder" would be less prone to the misunderstandings of the past especially in the absence of heavy documentation. It would be clearly evident that it is a function native to the j-cook framework and not SQL directly..

Just a suggestion..

Regards
v
The administrator has disabled public write access.

Re: "GroupBy" generator error in Models - prepareQuery 24 Jun 2013 15:35 #7634

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Ok, good suggestion.

I still can change this today or tomorrow.
I must do it fast to not create confusions.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: "GroupBy" generator error in Models - prepareQuery 25 Jun 2013 00:30 #7639

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Done.

replace
addGroupBy(...)
to
addGroupOrder(...)
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.082 seconds

Get Started