diff --git a/lib/grouped_scope/association_reflection.rb b/lib/grouped_scope/association_reflection.rb index f9ab1f4..53a9ba1 100644 --- a/lib/grouped_scope/association_reflection.rb +++ b/lib/grouped_scope/association_reflection.rb @@ -37,7 +37,10 @@ def verify_ungrouped_reflection end def create_grouped_association - active_record.send :has_many, name, options + active_record.send(macro, name, options) + association_proxy_class = options[:through] ? ActiveRecord::Associations::HasManyThroughAssociation : ActiveRecord::Associations::HasManyAssociation + active_record.send(:collection_reader_method, self, association_proxy_class) + active_record.reflections[name] = self active_record.grouped_scopes[@ungrouped_name] = true options[:grouped_scope] = true diff --git a/test/grouped_scope/self_grouping_test.rb b/test/grouped_scope/self_grouping_test.rb index b9c4a82..261c565 100644 --- a/test/grouped_scope/self_grouping_test.rb +++ b/test/grouped_scope/self_grouping_test.rb @@ -101,7 +101,7 @@ def setup # raise Employee.reflections[:grouped_scope_reports].inspect # assert_equal @e1_g1.reports.size, @e1_g1.group.reports.size - @e1_g1.reports + # @e1_g1.reports # @e1_g1.group.reports # @e1_g1.grouped_scope_reports end