33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/sequel/sqlite_pervasive_adapter.rb', line 33
def select_fields(hash)
new_hash = Hash.new{|k, v| k[v]= {}}
hash.each do |association, fields|
new_hash[association][:fields] = fields
if association == :self
new_hash[association][:model] = self.model
new_hash[association][:association_name] = self.model.table_name
elsif association.to_s.match /(\w+)__(\w+)/ new_hash[association][:association_name] = $2.to_s.upcase
new_hash[association][:model] = model.association_reflection($1.to_sym)[:class].association_reflection($2.to_sym)[:class]
else
raise(Sequel::Error, "Invalid #{model} association: #{association}") unless model.association_reflection(association)
new_hash[association][:association_name] = association.to_s.upcase
new_hash[association][:model] = model.association_reflection(association)[:class]
end
fields = fields + new_hash[association][:model].primary_key unless fields[0] == :*
new_hash[association][:fields] = fields
end
s = []
new_hash.each do |association, hash|
if hash[:fields].size == 1 and hash[:fields][0] == :*
s << "#{quoted_identifier(hash[:association_name], false)}.*".lit
else
s << hash[:fields].collect do |field|
raw_field_name = convert_aliased_col_to_real_col_with_model(field, hash[:model])
as_alias = ''
raw_field_name
if association != :self and ( hash[:model].primary_key.include? field or field_duplicate(new_hash, association, field) )
as_field_name = "#{hash[:association_name]}_#{raw_field_name}"
as_alias = "AS #{quoted_identifier(as_field_name, false)}"
end
"#{quoted_identifier(hash[:association_name], false)}.#{quoted_identifier(raw_field_name, false)} #{as_alias}".lit
end
end
end
clone(:select => s.flatten)
end
|