Skip to content

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

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions