Hello
ransack is awesome tool, but I have one question.
I have a table A which "has_many" B, and i search A by ":B_A_id_eq", ransack returns more than 2 records even I use result(:distinct => true), because there are more than 2 records in B which associate with same record in table A
Is there anyway to solve this problem?
Thanks
David H
Could you please create an application that reproduces the issue so that I can use it to inspect the problem? Thanks!
Thanks for the quick reply! I will create an application asap
by the way, result(:distinct => true).to_sql shows correct SQL query
+1
Would love to see this get fixed if it hasn't already, using distinct true is great if you're working with a small data set... but it can cause a full table scan.
Do we know what the root cause of this issue is?
I've found that if params[:q] contains key value pairs where the value is empty string, the SQL that is generated will chain LEFT OUTER JOINS, leading to lots of duplication.
You can get rid of this duplication by removing the empty key value pairs manually like so:
params[:q].delete_if{|k, v| v.blank? }
But, ideally the ransack gem would do this for you so this logic isn't spread all throughout your application.
Actually not sure if these are connected -- I was getting duplicated search results for a different reason.
Closed
Why was this Issue closed? I still get duplicated results when filtering over has_many associations.
Still getting duplicate results here as well.
@mortik @stcho any chance you could create a repo with the issue and point it here?
Closing. This would benefit from an example repo or better still a PR with a failing test.
Most helpful comment
Thanks for the quick reply! I will create an application asap
by the way, result(:distinct => true).to_sql shows correct SQL query