Skip to content

Commit

Permalink
Merge pull request #952 from activerecord-hackery/association_table_i…
Browse files Browse the repository at this point in the history
…ssue

Don't return association if table is nil
  • Loading branch information
gregmolnar authored Aug 18, 2018
2 parents 966f9c0 + 63ccf9f commit a346096
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Don't return association if table is nil
PR [952](https://github.com/activerecord-hackery/ransack/pull/952)

*Christian Gregg*

## Version 2.0.0 - 2018-08-09

* Add support for Active Record 5.2.1
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def build_or_find_association(name, parent = @base, klass = nil)

def find_association(name, parent = @base, klass = nil)
@join_dependency.instance_variable_get(:@join_root).children.detect do |assoc|
assoc.reflection.name == name &&
assoc.reflection.name == name && assoc.table &&
(@associations_pot.empty? || @associations_pot[assoc] == parent || !@associations_pot.key?(assoc)) &&
(!klass || assoc.reflection.klass == klass)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/ransack/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ module Ransack
.to eq s.result(distinct: true).send(all_or_load)
end

it 'evaluates joins with belongs_to join' do
s = Person.joins(:parent).ransack(parent_name_eq: 'Ernie').result(distinct: true)
expect(s).to be_an ActiveRecord::Relation
end

private

def remove_quotes_and_backticks(str)
Expand Down

0 comments on commit a346096

Please sign in to comment.