Question: Nested Join query enum values show up as integers in its json representation

Question

Nested Join query enum values show up as integers in its json representation

Answers 0
Added at 2016-12-21 19:12
Tags
Question

When doing a select of a nested association enum value and changing it to its json representation these values wont convert to strings, any other simple join value has its string representation.

Enum: (Example, real enum has more values)

enum category_type: [:gender, :another_value]

Query: (Example, real query has more joins and fields)

  def self.report
    select_fields = 'question_categories.category_type'

    joins(question: :question_category)
      .select(select_fields)
      .group('question_categories.category_type')
  end

JSON: Right Now

[{"id"=>nil, "category_type"=>0},
 {"id"=>nil, "category_type"=>1}]

JSON: What i want to see

[{"id"=>nil, "category_type"=>"gender"},
 {"id"=>nil, "category_type"=>"another value"}]

Thanks.

Answers
Source Show
◀ Wstecz