Comments (6)
Thredded dropped 4.1 compatibility finally.
If this gem doesn't support 4.1, the dependency version in gemspec should be bumped though.
from active_record_union.
I'm just going to add a note to the README since I can't say affirmatively which combos work and don't work.
ActiveRecordUnion is tested against Rails 4.2 and Rails 5.0. It may or may not work on Rails 4.0/4.1.
from active_record_union.
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
user.rb
:
has_many :enrollments
has_many :enrolled_courses, through: :enrollments
def courses
enrolled_courses.union(Course.open_to_institution(institution_ids))
end
course.rb
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
from active_record_union.
Oh, that looks like a real bug. Thanks for the detailed report.
from active_record_union.
@kapluni can you provide more insight into this error? I've tried to recreate the query you posted as well as the my_user.courses
query and everything works fine. I am having no problems with Postgres.
- What version of the
pg
gem are you using? (I'm on 0.18.4) - What version of
active_record_union
are you using? (Latest is 1.2.0) - What exactly is the Ruby code that produces the problem query? It can't be
my_user.courses
because the SQL query you posted doesn't includeinstitution_id
anywhere...unless there's some weird eager loading or something going on.
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
from active_record_union.
sorry for the slow respone
What version of the pg gem are you using? (I'm on 0.18.4)
same
What version of active_record_union are you using? (Latest is 1.2.0)
same
What exactly is the Ruby code that produces the problem query? It can't be my_user.courses because the SQL query you posted doesn't include institution_id anywhere...unless there's some weird eager loading or something going on.
i am using jsonapi-resources
, and it's loading the relationship as a related resource, via:
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!
from active_record_union.
Related Issues (20)
- Cannot union relation with includes HOT 6
- Support for sinatra-activerecord HOT 1
- There are different results of UNION subqueries depending on mysql version HOT 1
- Eager-loading and support for includes, joins and references HOT 2
- nil.union(something_not_nil) HOT 1
- Feature request: union relations and SQL strings HOT 1
- Associated scopes – Major security issue HOT 3
- Interested in supporting intersect and except? HOT 4
- Problem with (empty result).update_all
- union doesn't work for union of fields
- Union of multiple columns on 2 tables with no relationship
- Feature request: Test on Rails 6.0
- PG::SyntaxError: ERROR: syntax error at or near "desc"
- How can I get the UNION of 2 different tables HOT 1
- `union` ignored if used in a merge
- gem does not work with SQLServer
- Not binding polymorphic relation HOT 3
- Is flat union chaining possible? Is it preferable to nested? HOT 3
- Fails on Rails 5.0.0.beta3: undefined method `visitor' for ActiveRecord::Relation HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from active_record_union.