diff --git a/lib/ransack/nodes/grouping.rb b/lib/ransack/nodes/grouping.rb index 1bf70550..aeee6ae7 100644 --- a/lib/ransack/nodes/grouping.rb +++ b/lib/ransack/nodes/grouping.rb @@ -178,6 +178,13 @@ def write_attribute(name, val) end def read_attribute(name) + if self[name].nil? + stripped_name = name.dup + predicate = Predicate.detect_and_strip_from_string!(stripped_name) + aliased_attribute = context.ransackable_alias(stripped_name) + name = "#{aliased_attribute}_#{predicate}" unless aliased_attribute == stripped_name + end + if self[name].respond_to?(:value) self[name].value else diff --git a/spec/ransack/nodes/grouping_spec.rb b/spec/ransack/nodes/grouping_spec.rb index 2f23baf7..72f1ede6 100644 --- a/spec/ransack/nodes/grouping_spec.rb +++ b/spec/ransack/nodes/grouping_spec.rb @@ -106,6 +106,23 @@ module Nodes end end + describe "#read_attribute" do + let(:conditions) do + { + '0' => { + 'a' => { '0'=> { 'name' => 'parent_name', 'ransacker_args' => '' } }, + 'p' => 'cont', + 'v' => { '0' => { 'value' => 'John' } } + }, + } + end + before { subject.conditions = conditions } + + it "works with aliases" do + expect(subject.parent_name_cont).to eq("John") + expect(subject.daddy_cont).to eq("John") + end + end end end end