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
While working on #50297 I found another bug related to query constraints for Polymorphic associations. I am looking into this but I created an issue here as I suspect there might be similar issues related to the usage of Query constraints.
# frozen_string_literal: truerequire"bundler/inline"gemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}gem'rails','7.1'gem'sqlite3'gem'pry'endrequire"active_record"require"logger"require'minitest/autorun'ActiveRecord::Base.establish_connection(adapter: 'sqlite3',database: ':memory:')ActiveRecord::Schema.definedocreate_table:comments,force: truedo |t|
t.integer:tenant_idt.references:commentable,polymorphic: true,null: falset.string:bodyt.integer:positionendcreate_table:authors,force: truedo |t|
t.integer:tenant_idendendclassAuthor < ActiveRecord::Basequery_constraints:tenant_id,:idhas_many:comments,as: :commentableendclassComment < ActiveRecord::Basequery_constraints:tenant_id,:idbelongs_to:commentable,polymorphic: trueendclassBugTest < Minitest::Test# Case when Author with tenant_id existsdeftest_when_id_existsauthor_1=Author.create!(tenant_id: 1)author_2=Author.create!(tenant_id: 1)comment=Comment.create(tenant_id: 1,commentable_id: author_2.id,commentable_type: 'Author')# BUG: Makes a query with tenant_idassert_equalauthor_2.id,comment.commentable.idend# Case when Author with tenant_id does not existdeftest_when_id_does_not_existauthor=Author.create!(tenant_id: 11)comment=Comment.create(tenant_id: 11,commentable_id: author.id,commentable_type: 'Author')assert_equalauthor.id,comment.commentable&.idendend
Expected behavior
Actual behavior
System configuration
Rails version: 7.1.2
Ruby version: 2.7.8
The text was updated successfully, but these errors were encountered:
Steps to reproduce
While working on #50297 I found another bug related to query constraints for Polymorphic associations. I am looking into this but I created an issue here as I suspect there might be similar issues related to the usage of Query constraints.
Expected behavior
Actual behavior
System configuration
Rails version: 7.1.2
Ruby version: 2.7.8
The text was updated successfully, but these errors were encountered: