Module: ActiveRepository::Associations::ActiveRecordExtensions
- Defined in:
- lib/active_repository/associations.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#belongs_to_active_repository(association_id, options = {}) ⇒ Object
Defines belongs to type relation between ActiveRepository objects and ActivRecord Models.
Instance Method Details
#belongs_to_active_repository(association_id, options = {}) ⇒ Object
Defines belongs to type relation between ActiveRepository objects and ActivRecord Models.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_repository/associations.rb', line 14 def belongs_to_active_repository(association_id, = {}) = { :class_name => association_id.to_s.classify, :foreign_key => association_id.to_s.foreign_key }.merge() define_method(association_id) do [:class_name].constantize.find_by_id(send([:foreign_key])) end define_method("#{association_id}=") do |new_value| send "#{[:foreign_key]}=", new_value ? new_value.id : nil end create_reflection( :belongs_to, association_id.to_sym, , [:class_name].constantize ) end |