Ticket #9758: active_record_reflection_fix.patch
| File active_record_reflection_fix.patch, 1.7 kB (added by mindforge, 9 months ago) |
|---|
-
lib/active_record/reflection.rb
old new 110 110 111 111 private 112 112 def derive_class_name 113 name.to_s.camelize 113 parent_module = self.active_record.parent 114 [parent_module, name.to_s.camelize].reject{ |i| Object == i }.join('::') 114 115 end 115 116 end 116 117 … … 199 200 if through_reflection 200 201 options[:source_type] || source_reflection.class_name 201 202 else 202 class_name = name.to_s.camelize203 class_name = super 203 204 class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro) 204 205 class_name 205 206 end -
test/reflection_test.rb
old new 165 165 assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size 166 166 end 167 167 168 def test_reflection_class_name 169 reflection = ActiveRecord::Base.create_reflection(:has_many, :clients, {}, Firm) 170 assert_equal 'Client', reflection.class_name 171 end 172 173 def test_reflection_class_name_for_classes_nested_in_modules 174 reflection = ActiveRecord::Base.create_reflection(:has_many, :clients, {}, MyApplication::Business::Firm) 175 assert_equal 'MyApplication::Business::Client', reflection.class_name 176 end 177 168 178 private 169 179 def assert_reflection(klass, association, options) 170 180 assert reflection = klass.reflect_on_association(association)