leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
535 stars 215 forks source link

Association issue on FROM clause #343

Open hebergentilin opened 7 years ago

hebergentilin commented 7 years ago

Consider the sequence of this columns:

g.column name: '#', attribute: 'id', assoc: [:register] do |invoice|
  invoice.register.id
end

g.column name: 'Student', attribute: 'name', assoc: [:register, :student] do |invoice|
  invoice.register.student.name
end

When searching by student.name, it raises the following error:

PG::UndefinedTable: ERROR: missing input to table "students" at clause FROM

SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "invoices" INNER JOIN "registers" ON "registers"."id" = "invoices"."register_id" AND "registers"."company_id" = $1 WHERE (registers.status = 1 AND invoices.status = 1) AND "invoices"."company_id" = $2 AND (  students.name ILIKE '%d%') LIMIT 20 OFFSET 0) subquery_for_count

But, switching the columns position, the error gone:

g.column name: 'Student', attribute: 'name', assoc: [:register, :student] do |invoice|
  invoice.register.student.name
end

g.column name: '#', attribute: 'id', assoc: [:register] do |invoice|
  invoice.register.id
end