File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- require 'active_record'
1+ begin
2+ require 'active_record'
23
3- ::ActiveRecord ::Associations ::Builder ::HasOne . class_eval do
4- # Based on
5- # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/builder/collection_association.rb#L50
6- # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/builder/singular_association.rb#L11
7- def self . define_accessors ( mixin , reflection )
8- super
9- name = reflection . name
10- mixin . class_eval <<-CODE , __FILE__ , __LINE__ + 1
11- def #{ name . to_s } _id
12- association(:#{ name } ).reader.try(:id)
13- end
14- CODE
4+ ::ActiveRecord ::Associations ::Builder ::HasOne . class_eval do
5+ # Based on
6+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/builder/collection_association.rb#L50
7+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/builder/singular_association.rb#L11
8+ def self . define_accessors ( mixin , reflection )
9+ super
10+ name = reflection . name
11+ mixin . class_eval <<-CODE , __FILE__ , __LINE__ + 1
12+ def #{ name . to_s } _id
13+ association(:#{ name } ).reader.try(:id)
14+ end
15+ CODE
16+ end
1517 end
18+ rescue LoadError
19+ # active_record can't be loaded so we shouldn't try to monkey-patch it.
1620end
You can’t perform that action at this time.
0 commit comments