-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails on Rails 4.1 + PostgreSQL: bind supplies 2 parameters, but prepared statement requires 1 #8
Comments
Thredded dropped 4.1 compatibility finally. |
I'm just going to add a note to the README since I can't say affirmatively which combos work and don't work.
|
I am seeing a similar issue on rails 4.2.6. Course Load (0.4ms) SELECT "courses".* FROM ( (SELECT "courses".* FROM "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" WHERE "enrollments"."user_id" = $1) UNION (SELECT "courses".* FROM "courses" WHERE 1=0 AND "courses"."open_to_institution" = $2) ) "courses" [["user_id", 1], ["open_to_institution", "t"], ["user_id", 1], ["open_to_institution", "t"]]
PG::ProtocolViolation: ERROR: bind message supplies 4 parameters, but prepared statement "a31" requires 2
: SELECT "courses".* FROM ( (SELECT "courses".* FROM "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" WHERE "enrollments"."user_id" = $1) UNION (SELECT "courses".* FROM "courses" WHERE 1=0 AND "courses"."open_to_institution" = $2) ) "courses"' duration=55.75 view=0.00 db=5.57 params={"include"=>"courses", "id"=>"1"} log_level=exception timestamp=2016-08-09 13:34:43 UTC transaction_id=06def7abb5a345343b76 user_id=1 exception_message=ERROR: bind message supplies 4 parameters, but prepared statement "a31" requires 2
has_many :enrollments
has_many :enrolled_courses, through: :enrollments
def courses
enrolled_courses.union(Course.open_to_institution(institution_ids))
end
class Course < ActiveRecord::Base
include Taggable
belongs_to :institution
has_many :enrollments
scope :open_to_institution, ->(institution_id) { where(institution_id: institution_id).where(open_to_institution: true) }
end |
Oh, that looks like a real bug. Thanks for the detailed report. |
@kapluni can you provide more insight into this error? I've tried to recreate the query you posted as well as the
With "group" == "course", "category" == "institution", this is what I get: User.new(id: 1).groups.union(Group.in_category([1,2,3])).to_a Group Load (0.5ms)
SELECT "groups".* FROM (
(SELECT "groups".* FROM "groups" INNER JOIN "enrollments"
ON "groups"."id" = "enrollments"."group_id"
WHERE "enrollments"."user_id" = $1 AND (1=0))
UNION
(SELECT "groups".* FROM "groups"
WHERE "groups"."category_id" IN (1, 2, 3)
AND "groups"."public" = $2)
) "groups"
[["user_id", 1], ["public", "t"]] class User < ActiveRecord::Base
has_many :enrollments
has_many :groups, through: :enrollments
end
class Enrollment < ActiveRecord::Base
belongs_to :user
belongs_to :group
end
class Group < ActiveRecord::Base
belongs_to :category
has_many :enrollments
scope :in_category, ->(category_id) { where(category: category_id).where(public: true) }
end
class Category < ActiveRecord::Base
has_many :groups
end |
sorry for the slow respone
same
same
i am using define_method foreign_key do
records = public_send(associated_records_method_name)
return records.collect do |record|
record.public_send(relationship.resource_klass._primary_key)
end
end unless method_defined?(foreign_key) record in this case would be the user, and course is the relationship. i just ran into a similar case with another, similar pattern in my code. thanks very much for looking into this! |
https://travis-ci.org/thredded/thredded/jobs/121800665
Only getting this error on the specific combination of PostgreSQL + Rails 4.1. All the other builds are passing.
The text was updated successfully, but these errors were encountered: