Module: MassiveRecord::ORM::Schema::ColumnInterface

Extended by:
ActiveSupport::Concern
Included in:
Column
Defined in:
lib/massive_record/orm/schema/column_interface.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_field(*args) ⇒ Object

Same as defined in class method, but also sets the default value in current object it was called from.



74
75
76
77
78
# File 'lib/massive_record/orm/schema/column_interface.rb', line 74

def add_field(*args)
  new_field = self.class.add_field(*args)
  method = "#{new_field.name}="
  send(method, new_field.default) if respond_to? method
end

#attributes_to_row_values_hash(only_attr_names = []) ⇒ Object

TODO : Need to be cleaned up after we implement the has_many method



83
84
85
86
87
88
89
90
91
92
# File 'lib/massive_record/orm/schema/column_interface.rb', line 83

def attributes_to_row_values_hash(only_attr_names = [])
  values = Hash.new

  attributes_schema.each do |attr_name, orm_field|
    next unless only_attr_names.empty? || only_attr_names.include?(attr_name)
    values[orm_field.column] = send(attr_name)
  end

  values
end