Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

broken hash conditions when querying for an activerecord object on a joined table #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,13 @@ module ActiveRecord
Person.first.authored_article_comments.joins(:article).first.should eq Comment.first
end

it 'does not break hash conditions that specify the table name' do
person = Comment.first.article.person
person.should be_present
Comment.joins(:article).where(articles: {person_id: person}).should be_present
Comment.joins(:article).where(articles: {person: person}).should be_present
end

it 'joins polymorphic belongs_to associations' do
relation = Note.joins{notable(Article)}
relation.to_sql.should match /#{Q}notes#{Q}.#{Q}notable_type#{Q} = 'Article'/
Expand Down