Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

How to get a raw result(no Hanami::Entity) from a query. #477

@wuarmin

Description

@wuarmin

Hello,

I have following query:

def identifier_register
  fr_cost_notes.select_group(:identifier).
  select_append {
    `array_agg(distinct "month") "months"`
  }.
  where(company_id: company_id, profit_center_id: profit_center_ids) {
    (month >= month_from) & (month <= month_until)
  }.to_a
end

and expect a unmapped result like

[
   {
        :identifier => "BALBOA",
        :months => [201601, 201602]
    },
    {
        :identifier => "ROCKY",
        :months => [201601, 201602, 201801]
    }
]

but get an array of Hanami::Entities without "months", because it is not defined at entity-schema.
I think this worked in previous hanami-versions, but I'm not sure.

Just for info: To workaround the issue, I ended with a hack like this.

def identifier_register
  sql = fr_cost_notes.select_group(:identifier).
  select_append {
    `array_agg(distinct "month") "months"`
  }.
  where(company_id: company_id, profit_center_id: profit_center_ids) {
    (month >= month_from) & (month <= month_until)
  }.dataset.sql

  fetch(sql, false)
end

best regards

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions