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

how should I proceed to display the number of filtered posts related to a user #2

Open
ghost opened this issue Apr 19, 2012 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 19, 2012

in order to get a better understanding of ransack, I forked it and split the demo in 2 parts, ransack_simple_demo and ransack_advanced_demo . You can get a copy the simple at https://github.com/erwin/ransack_simple_demo
I moved to MySQL and added the Twitter-Bootstrap framework.. also updated the gem file ( Machinist 2 for db:seed) and added will_paginate

I have question about it :
when I search on user parameters and post parameter, ( non distinct) I get the following generated sql :

SELECT users.* FROM users LEFT OUTER JOIN posts ON posts.user_id = users.id WHERE (posts.title LIKE '%pa%') ORDER BY users.last_name ASC LIMIT 10 OFFSET 0

is there a way to display an additional column with the number of filtered posts for each listed user... ? this is possible in pure SQL, using COUNT and GROUP BY ...
SELECT users.*, COUNT(posts.id) FROM users LEFT OUTER JOIN posts ON posts.user_id = users.id WHERE (posts.title LIKE '%pa%') GROUP BY users.id ORDER BY users.last_name ASC LIMIT 10 OFFSET 0;

but how to do it using ransack ?

thanks for feedback

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

0 participants