@shops = Shop.includes(concept: [:chain]).where(where_clause_map).order("#{attribute} #{ordering}").limit(params[:rowCount]).offset(offset)
Where:
Shop includes concept and in turn concept includes chain
and
where_clause_map looks like: {"id" => "[1,2]", "shop_concepts" => "1" ,"shop_chains.id"=> "1"}
NOTE: Using an array as in: "id" => "[1,2]" , causes the query to run as id IN (1, 2)