You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
When using default_scope and has_many :through association, squeel seems to apply incorrect scope.
Here is a reproduction script.
gem'activerecord','4.2.0'gem'squeel','1.2.3'require'active_record'require'minitest/autorun'require'logger'require'squeel'# Ensure backward compatibility with Minitest 4Minitest::Test=MiniTest::Unit::TestCaseunlessdefined?(Minitest::Test)# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: 'sqlite3',database: ':memory:')ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedocreate_table:users,force: truedo |t|
endcreate_table:posts,force: truedo |t|
t.integer:user_idt.boolean:activeendcreate_table:comments,force: truedo |t|
t.integer:post_idendendclassUser < ActiveRecord::Basehas_many:postshas_many:comments,through: :postsendclassPost < ActiveRecord::Basehas_many:commentsdefault_scope{where{active == true}}endclassComment < ActiveRecord::Basebelongs_to:postendclassBugTest < Minitest::Testdeftest_default_scopeuser=User.create!user.posts << Post.create!user.posts.first.comments << Comment.create!assert_equal1,user.comments.countassert_equal1,Comment.countendend
squeel applied active == true to Comment so that this test failed and got following error.
ActiveRecord::StatementInvalid: SQLite3::SQLException:
no such column: comments.active:
SELECT COUNT(*) FROM "comments"
INNER JOIN "posts" ON "comments"."post_id" = "posts"."id"
WHERE "comments"."active" = 't' AND "posts"."user_id" = ?
Please let me know if there is anything I can help.
Thanks!
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
When using
default_scope
andhas_many :through
association, squeel seems to apply incorrect scope.Here is a reproduction script.
squeel
appliedactive == true
toComment
so that this test failed and got following error.Please let me know if there is anything I can help.
Thanks!
The text was updated successfully, but these errors were encountered: