Closed krzyzak closed 8 years ago
Thanks. Merged and released new gem version with the fix.
As far as enhancing the queries to support search by joined table, the most important criteria to me would be to ensure backwards compatibility. The example API you gave is congruent with the normal Rails API is a plus, but it implies some functionality that might be complicated to implement. array_has(blog: { flags: ["spam"], otherflags: ["important"] })
. A simpler API might be array_has(:blog, :flags, ["spam"])
If there are 3 args we use the 1st as the table name. Probably worth thinking more about this -- this was just my initial thoughts.
Hi,
First of all – thanks for creating this gem, it’s really useful in my project.
I recently encountered one issue though. I’ve got
Blog
andBlogPost
models with one–to–many relation. Both models contains column "flag" (array). When I’m searching forBlogPost.array_has(:flag, ["spam"])
, everything works just fine. Problem is with column ambiguity when I’m joining Blog:In my PR, instead of using
"flags" @> ARRAY['spam']::character
it uses"blog_posts"."flags"
which solves that issue.The only thing which I’m not really sure about is how to add ability to search by
blog.flags
– it would probably require some API change (eg. (array_has(blog: { flags: ["spam"] }, blog_posts: { flag: ["casino"] })
) – what do you think about that?