Module: MultipleTableInheritance::Child::Base::FinderMethods

Defined in:
lib/multiple_table_inheritance/child/base.rb

Instance Method Summary collapse

Instance Method Details

#find_by_id(*args) ⇒ Object



117
118
119
# File 'lib/multiple_table_inheritance/child/base.rb', line 117

def find_by_id(*args)
  send("find_by_#{parent_association_name}_id", *args)
end

#find_by_sql(*args) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/multiple_table_inheritance/child/base.rb', line 105

def find_by_sql(*args)
  child_records = super(*args)
  
  ids = child_records.collect(&:id)
  parent_records = parent_association_class.as_supertype.find_all_by_id(ids)
  
  child_records.each do |child|
    parent = parent_records.find { |parent| parent.id == child.id }
    child.send(:parent_association=, parent) if parent
  end
end