Class: Hold::Sequel::PropertyMapper::Identity

Inherits:
Hold::Sequel::PropertyMapper show all
Defined in:
lib/hold/sequel/property_mapper/identity.rb

Instance Attribute Summary

Attributes inherited from Hold::Sequel::PropertyMapper

#property, #property_name, #repository

Instance Method Summary collapse

Methods inherited from Hold::Sequel::PropertyMapper

#initialize, #load_values, #post_delete, #post_update, #pre_delete, #pre_insert, #pre_update, setter_dependencies_for

Constructor Details

This class inherits a constructor from Hold::Sequel::PropertyMapper

Instance Method Details

#build_insert_row(entity, table, row, id = nil) ⇒ Object

the ID needs to go into insert rows for /all/ tables of the repo



14
15
16
17
18
# File 'lib/hold/sequel/property_mapper/identity.rb', line 14

def build_insert_row(entity, table, row, id=nil)
  id ||= entity[@property_name] or return
  id_column = @repository.table_id_column(table)
  row[id_column] = id
end

#build_update_row(entity, table, row) ⇒ Object

we don’t update the ID - considered immutable



21
22
# File 'lib/hold/sequel/property_mapper/identity.rb', line 21

def build_update_row(entity, table, row)
end

#columns_aliases_and_tables_for_select(preferred_table = @repository.main_table) ⇒ Object



3
4
5
6
# File 'lib/hold/sequel/property_mapper/identity.rb', line 3

def columns_aliases_and_tables_for_select(preferred_table=@repository.main_table)
  qualified = qualified_column_name(preferred_table)
  return [qualified], [qualified.as(:id)], [preferred_table]
end

#load_value(row, id = nil, version = nil) ⇒ Object



29
30
31
# File 'lib/hold/sequel/property_mapper/identity.rb', line 29

def load_value(row, id=nil, version=nil)
  row[:id]
end

#make_filter(value, columns_mapped_to) ⇒ Object



33
34
35
# File 'lib/hold/sequel/property_mapper/identity.rb', line 33

def make_filter(value, columns_mapped_to)
  {columns_mapped_to.first => value}
end

#make_multi_filter(values, columns_mapped_to) ⇒ Object



37
38
39
# File 'lib/hold/sequel/property_mapper/identity.rb', line 37

def make_multi_filter(values, columns_mapped_to)
  {columns_mapped_to.first => values}
end

#post_insert(entity, rows, last_insert_id = nil) ⇒ Object

After a successful insert, we assign the last_insert_id back onto the entity’s id property:



25
26
27
# File 'lib/hold/sequel/property_mapper/identity.rb', line 25

def post_insert(entity, rows, last_insert_id=nil)
  entity[@property_name] = last_insert_id if last_insert_id
end

#qualified_column_name(preferred_table = @repository.main_table) ⇒ Object



8
9
10
11
# File 'lib/hold/sequel/property_mapper/identity.rb', line 8

def qualified_column_name(preferred_table=@repository.main_table)
  id_column = @repository.table_id_column(preferred_table)
  Sequel::SQL::QualifiedIdentifier.new(preferred_table, id_column)
end