Skip to content

Commit 18cb4f6

Browse files
authored
Merge pull request #1190 from cerebris/arel_sql_pluck_fields
Wrap pluck fields with Arel.sql
2 parents fb35962 + e8cad46 commit 18cb4f6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/jsonapi/active_relation_resource_finder.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ def find_fragments(filters, options = {})
6464
records = find_records(filters, options)
6565

6666
table_name = _model_class.table_name
67-
pluck_fields = ["#{concat_table_field(table_name, _primary_key)} AS #{table_name}_#{_primary_key}"]
67+
pluck_fields = [Arel.sql("#{concat_table_field(table_name, _primary_key)} AS #{table_name}_#{_primary_key}")]
6868

6969
cache_field = attribute_to_model_field(:_cache_field) if options[:cache]
7070
if cache_field
71-
pluck_fields << "#{concat_table_field(table_name, cache_field[:name])} AS #{table_name}_#{cache_field[:name]}"
71+
pluck_fields << Arel.sql("#{concat_table_field(table_name, cache_field[:name])} AS #{table_name}_#{cache_field[:name]}")
7272
end
7373

7474
model_fields = {}
7575
attributes = options[:attributes]
7676
attributes.try(:each) do |attribute|
7777
model_field = attribute_to_model_field(attribute)
7878
model_fields[attribute] = model_field
79-
pluck_fields << "#{concat_table_field(table_name, model_field[:name])} AS #{table_name}_#{model_field[:name]}"
79+
pluck_fields << Arel.sql("#{concat_table_field(table_name, model_field[:name])} AS #{table_name}_#{model_field[:name]}")
8080
end
8181

8282
fragments = {}
@@ -204,21 +204,21 @@ def find_related_monomorphic_fragments(source_rids, relationship, included_key,
204204
records = related_klass.apply_filters(records, filters, filter_options)
205205

206206
pluck_fields = [
207-
"#{primary_key_field} AS #{_table_name}_#{_primary_key}",
208-
"#{concat_table_field(table_alias, related_klass._primary_key)} AS #{table_alias}_#{related_klass._primary_key}"
207+
Arel.sql("#{primary_key_field} AS #{_table_name}_#{_primary_key}"),
208+
Arel.sql("#{concat_table_field(table_alias, related_klass._primary_key)} AS #{table_alias}_#{related_klass._primary_key}")
209209
]
210210

211211
cache_field = related_klass.attribute_to_model_field(:_cache_field) if options[:cache]
212212
if cache_field
213-
pluck_fields << "#{concat_table_field(table_alias, cache_field[:name])} AS #{table_alias}_#{cache_field[:name]}"
213+
pluck_fields << Arel.sql("#{concat_table_field(table_alias, cache_field[:name])} AS #{table_alias}_#{cache_field[:name]}")
214214
end
215215

216216
model_fields = {}
217217
attributes = options[:attributes]
218218
attributes.try(:each) do |attribute|
219219
model_field = related_klass.attribute_to_model_field(attribute)
220220
model_fields[attribute] = model_field
221-
pluck_fields << "#{concat_table_field(table_alias, model_field[:name])} AS #{table_alias}_#{model_field[:name]}"
221+
pluck_fields << Arel.sql("#{concat_table_field(table_alias, model_field[:name])} AS #{table_alias}_#{model_field[:name]}")
222222
end
223223

224224
rows = records.pluck(*pluck_fields)
@@ -265,9 +265,9 @@ def find_related_polymorphic_fragments(source_rids, relationship, options = {})
265265
related_type = concat_table_field(_table_name, relationship.polymorphic_type)
266266

267267
pluck_fields = [
268-
"#{primary_key} AS #{_table_name}_#{_primary_key}",
269-
"#{related_key} AS #{_table_name}_#{relationship.foreign_key}",
270-
"#{related_type} AS #{_table_name}_#{relationship.polymorphic_type}"
268+
Arel.sql("#{primary_key} AS #{_table_name}_#{_primary_key}"),
269+
Arel.sql("#{related_key} AS #{_table_name}_#{relationship.foreign_key}"),
270+
Arel.sql("#{related_type} AS #{_table_name}_#{relationship.polymorphic_type}")
271271
]
272272

273273
relations = relationship.polymorphic_relations

0 commit comments

Comments
 (0)