Forum: Ruby on Rails rails query filtering

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2012-04-19 17:58
(Received via mailing list)
I am trying to set up a filter form, in which I can select users based
on User attributes and get a count of the user's post filtered on Post
attributes

this generated query runs very well,

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

and I can display all selected users info :
%tr
  %td= user.id
  %td= user.first_name
  %td= user.last_name
  %td= user.email

but how can I add a column with the number of filtered posts for each
user ?

thanks for your feedback  [using Rails 3.2.3 )
This topic is locked and can not be replied to.