Module: RemoteEntity::EntityRecord::Assocations::ClassMethods

Defined in:
lib/remote_entity/entity_record_associations.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to_remote(association_id, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/remote_entity/entity_record_associations.rb', line 10

def belongs_to_remote(association_id, options = {})
  if options[:class_name].nil?
    options[:class_name] = association_id.to_s.camelize.to_sym 
  end
  
  association_class = 
      Object.const_get(options[:class_name].to_sym)
    
  define_accessible(association_id, options, association_class)
  define_constructors(association_id, options, association_class)
  
  if options[:dependent] == :destroy
    define_destroy(association_id, options, association_class)
    after_destroy "destroy_#{association_id}".to_sym
  end
end