1

I have this query, but I get this error: undefined method `where' for #Array:0x0000000443cd18

@kpig = KpiGroups.find_by_sql('select * from (
      select lk.login,sdf.* from (select kg.id, kg.name as "GROUP_NAME", kt.name, kt.id as "KPI"
      from spartacus.kpi_groups kg, spartacus.kpi_types kt left outer join (select kpiid as kpi, max(max_value) as max_val ,min(min_value) as min_val
      from (select kpiid,max_value,min_value from spartacus.stations group by  max_value,min_value,kpiid) group by kpiid) sel on(sel.kpi=kt.id) where  kt.parentcatalogid=kg.id) sdf
      left outer join spartacus.LKBs lk on lk.kpi_id=sdf."KPI" )').where("login = '#{current_user.login}'")

2 Answers 2

1

You can do:

    @kpig = KpiGroups.find_by_sql("select * from (
  select lk.login,sdf.* from (select kg.id, kg.name as GROUP_NAME, kt.name, kt.id as KPI
  from spartacus.kpi_groups kg, spartacus.kpi_types kt left outer join (select kpiid as kpi, max(max_value) as max_val ,min(min_value) as min_val
  from (select kpiid,max_value,min_value from spartacus.stations group by  max_value,min_value,kpiid) group by kpiid) sel on(sel.kpi=kt.id) where  kt.parentcatalogid=kg.id) sdf
  left outer join spartacus.LKBs lk on lk.kpi_id=sdf.KPI ) where login='#{current_user.login}'")
Sign up to request clarification or add additional context in comments.

Comments

1

find_by_sql method returns Array instead of ActiveRecord::Relation instance.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.