params support in blocks, nested includes etc Co-authored-by: Jodi Showers <jodi@nnovation.ca> Co-authored-by: Ryan O'Donnell <ryan@gocleary.com> Co-authored-by: Les Fletcher <les.fletcher@gmail.com> Co-authored-by: Ankit gupta <ankit.gupta8898@gmail.com> Co-authored-by: Masato Ohba <over.rye@gmail.com> Co-authored-by: Shuhei Kitagawa <shuhei.kitagawa@c-fo.com> Co-authored-by: Zino <rhu5@u.rochester.edu> Co-authored-by: Carlos Solares <csolares23@gmail.com> Co-authored-by: Brandon Buck <lordizuriel@gmail.com> Co-authored-by: Daniel Roux <xuoroux@gmail.com> Co-authored-by: Dillon Welch <daw0328@gmail.com>
		
			
				
	
	
		
			21 lines
		
	
	
		
			819 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			819 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # frozen_string_literal: true
 | |
| 
 | |
| if defined?(::ActiveRecord)
 | |
|   ::ActiveRecord::Associations::Builder::HasOne.class_eval do
 | |
|     # Based on
 | |
|     # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/builder/collection_association.rb#L50
 | |
|     # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/builder/singular_association.rb#L11
 | |
|     def self.define_accessors(mixin, reflection)
 | |
|       super
 | |
|       name = reflection.name
 | |
|       mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
 | |
|         def #{name}_id
 | |
|           # if an attribute is already defined with this methods name we should just use it
 | |
|           return read_attribute(__method__) if has_attribute?(__method__)
 | |
|           association(:#{name}).reader.try(:id)
 | |
|         end
 | |
|       CODE
 | |
|     end
 | |
|   end
 | |
| end
 |