Trying to use Arel to query and count. For example, if I have posts in a blog that have categories, related through a post_categories table...how could I get all posts with four categories?? #help
@Hooper Here it is in arel. My version doesn't support WITH so I did a subquery. (Models are users/roles but the relationship is the same.)
user_t = User.arel_table
user_role_t = Arel::Table.new(:roles_users)
role_t = Role.arel_table
subquery = user_t.
join(user_role_t).on(user_role_t[:user_id].eq(user_t[:id])).
join(role_t).on(user_role_t[:role_id].eq(role_t[:id])).
group(user_t[:id]).
having("count(*) > 2").
project(user_t[:id])
User.where(user_t[:id].in(subquery))