52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/praxis-mapper/sequel_compat.rb', line 52
def _load_associated_objects(opts, dynamic_opts=OPTS)
return super if self.identity_map.nil?
target = opts.associated_class
key = opts[:key]
case opts[:type]
when :many_to_one
val = if key.kind_of?(Array)
@values.values_at(*key)
else
@values[key]
end
return nil if val.nil?
self.identity_map.get(target, target.primary_key => val)
when :one_to_many
self.identity_map.all(target, key => [pk] )
when :many_to_many
join_model = opts[:join_model].constantize
left_key = opts[:left_key]
right_key = opts[:right_key]
right_values = self.identity_map.
all(join_model, left_key => Array(values[primary_key])).
collect(&right_key)
self.identity_map.all(target, target.primary_key => right_values )
else
raise "#{opts[:type]} is not currently supported"
end
end
|