Method: Og::SqlStore#read_one

Defined in:
lib/og/store/sql.rb

#read_one(res, klass, options = nil) ⇒ Object

Deserialize one object from the ResultSet.



1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'lib/og/store/sql.rb', line 1068

def read_one(res, klass, options = nil)
  return nil if res.blank?

  if options and join_relations = options[:include]
    join_relations = [join_relations].flatten.collect do |n| 
      klass.relation(n) 
    end
  end

  res_row = res.next
  
  # causes STI classes to come back as the correct child class 
  # if accessed from the superclass.
  
  klass = Og::Entity::entity_from_string(res_row[0]) if klass.schema_inheritance?
  obj = klass.og_allocate(res_row, 0)

  if options and options[:select]
    read_row(obj, res, res_row, 0)
  else
    obj.og_read(res_row)
    read_join_relations(obj, res_row, 0, join_relations) if join_relations
  end

  return obj

ensure
  res.close
end