ruby on rails - Ransack - search by two ids collection -
let's have following models:
user has_many :posts post belongs_to :user and have following data in database:
user(id: 1) user(id: 2) post(id: 1, user_id: 1) post(id: 2, user_id: 1) post(id: 3, user_id: 1) i build ransack search returns users , matches following criteria:
- user has @ least 1 post id in (1, 2)
- and user has @ least 1 post id in (3, 4, 5, 6).
it should return: user(id: 1), beacause matches criteria.
i tried play "advanced mode" http://ransack-demo.herokuapp.com/users/advanced_search , possible define grouping criteria 2 conditions, generates sql 1 join operation only:
select distinct "users".* "users" left outer join "posts" on "posts"."user_id" = "users"."id" ((("posts"."id" in (1, 2)) , ("posts"."id" in (3, 4, 5, 6)))) i expected this:
select distinct "users".* "users" left outer join "posts" "posts_x" on "posts_x"."user_id" = "users"."id" left outer join "posts" "posts_y" on "posts_y"."user_id" = "users"."id" ((("posts_x"."id" in (1, 2)) , ("posts_y"."id" in (3, 4, 5, 6)))) is possible achieve ransack?
Comments
Post a Comment