Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order only check columns, why not checking additional values requested via SELECT #21

Open
ZenCocoon opened this issue Aug 23, 2009 · 3 comments

Comments

@ZenCocoon
Copy link

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 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

@nicolasblanco
Copy link

Yeah, I like this.

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.

Nicolas.

@ghost
Copy link

ghost commented Sep 12, 2009

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.

@ZenCocoon
Copy link
Author

Hi Ben,

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
...

Please let me know if it's still blurred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants