Arel + Rails 4.2 causing problems (bindings being lost)
I know this question is a bit old, but the error sounded familiar. I had some notes and our solution in a repository, so I thought I'd share.
The error we were receiving was:
PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1
So as you can see, our situation is a bit different. We didn't have 8 bind values. However, our single bind value was still being clobbered. I changed the naming of things to keep it general.
first_level = Blog.all_commentssecond_level = Comment.where(comment_id: first_level.select(:id))third_level = Comment.where(comment_id: second_level.select(:id))
Blog.all_comments
is where we have the single bind value. That's the piece we're losing.
union = first_level.union second_levelunion2 = Comment.from( Comment.arel_table.create_table_alias union, :comments).union third_levelrelation = Comment.from(Comment.arel_table.create_table_alias union2, :comments)
We created a union much like you except that we needed to union three different queries.
To get the lost bind values at this point, we did a simple assignment. In the end, this is a little simpler of a case than yours. However, it may be helpful.
relation.bind_values = first_level.bind_valuesrelation
By the way, here's the GitHub issue we found while working on this. It doesn't appear to have any updates since this question was posted though.