Module: Loco::Associatable
- Included in:
- Model
- Defined in:
- lib/motion-loco/associatable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
121 122 123 |
# File 'lib/motion-loco/associatable.rb', line 121 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#initialize(properties = {}) ⇒ Object
5 6 7 8 9 |
# File 'lib/motion-loco/associatable.rb', line 5 def initialize(properties={}) super initialize_relationships self end |
#initialize_relationships ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/motion-loco/associatable.rb', line 11 def initialize_relationships self.class.get_class_relationships.select{|relationship| relationship[:has_many] }.each do |relationship| has_many_class = relationship[:class_name] ? relationship[:class_name].to_s.classify.constantize : relationship[:has_many].to_s.classify.constantize self.send("#{relationship[:has_many]}=", RecordArray.new(relationship: relationship, item_class: has_many_class, belongs_to: self)) self.send("#{relationship[:has_many].to_s.singularize}_ids=", []) end end |