You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like the order option only accept valid columns names. What about additional values requested with SELECT.
Example :
SELECT users.*, COUNT(1) as count FROM ... ORDER BY count ASC
In this case, ordering by count can be extremely useful but doesn't look supported right now.
As quick workaround creating the named "scope ascend_by_count" and "descend_by_count" makes the job but still overload your models far to quick while adding such feature to searchlogic would keep things light and clean.
Thanks again for this great lib and excellent rewrite,
Warm regards,
Sebastien Grosjean - ZenCocoon
The text was updated successfully, but these errors were encountered:
I often want to order asc/desc using the count of an associated class.
When you use a counter_cache this is pretty easy to do using the counter_cache column but I don't want to use counter_caches everywhere and every time.
Hi Sebastien, I'm not sure I follow, how would you dynamically create that scope? I guess you cold make an exception for count if that is an AR default.
Didn't look the inside of named scope system yet (I actually should). The fact is that as of now, it seems that you allow as order, only existing column names from the tables queried.
I my case, I'm looking to also allow values defined by the SELECT parameter. It can be "count" as shown in the previous example but also different values depending your named scope
Example :
named_scope :select_with_author_name_as_writter,
:select => "posts.*, authors.name AS writter",
:joins => "LEFT OUTER JOIN authors ON authors.id = posts.author_id"
Post.select_with_author_name_as_writter.descend_by_writter
NoMethodError: undefined method `descend_by_writter' for #Class:0x101d8dc48
...
Hi Ben,
Looks like the order option only accept valid columns names. What about additional values requested with SELECT.
Example :
SELECT
users
.*, COUNT(1) as count FROM ... ORDER BY count ASCIn this case, ordering by count can be extremely useful but doesn't look supported right now.
As quick workaround creating the named "scope ascend_by_count" and "descend_by_count" makes the job but still overload your models far to quick while adding such feature to searchlogic would keep things light and clean.
Thanks again for this great lib and excellent rewrite,
Warm regards,
Sebastien Grosjean - ZenCocoon
The text was updated successfully, but these errors were encountered: