Module: ZTK::DSL::Core::Relations::BelongsTo Private
- Defined in:
- lib/ztk/dsl/core/relations/belongs_to.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary (collapse)
- + (Object) included(base) private
Instance Method Summary (collapse)
- - (Object) belongs_to_references private
- - (Object) get_belongs_to_reference(key) private
- - (Object) save_belongs_to_references private
- - (Object) set_belongs_to_reference(key, value) private
Class Method Details
+ (Object) included(base)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 10 11 12 |
# File 'lib/ztk/dsl/core/relations/belongs_to.rb', line 7 def self.included(base) base.class_eval do base.add_relation(:belongs_to) base.send(:extend, ZTK::DSL::Core::Relations::BelongsTo::ClassMethods) end end |
Instance Method Details
- (Object) belongs_to_references
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/ztk/dsl/core/relations/belongs_to.rb', line 14 def belongs_to_references @belongs_to_references ||= {} end |
- (Object) get_belongs_to_reference(key)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 22 23 24 25 26 |
# File 'lib/ztk/dsl/core/relations/belongs_to.rb', line 18 def get_belongs_to_reference(key) if belongs_to_references.key?(key) belongs_to_references[key] else key_id = send("#{key}_id") item = key.to_s.classify.constantize.find(key_id).first belongs_to_references[key] = item end end |
- (Object) save_belongs_to_references
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 44 45 |
# File 'lib/ztk/dsl/core/relations/belongs_to.rb', line 39 def save_belongs_to_references belongs_to_references.each do |key, dataset| dataset.each do |data| # do something to store the data somewhere end end end |
- (Object) set_belongs_to_reference(key, value)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ztk/dsl/core/relations/belongs_to.rb', line 28 def set_belongs_to_reference(key, value) belongs_to_references[key] = value attributes.merge!("#{key}_id".to_sym => value.id) klass = self.class.to_s.demodulize.downcase.pluralize many = value.send(klass) many << self many.uniq! end |