When two associations referring to the same model are joined, ActiveRecord
uses a table alias for one of these joins. To make it work with WiceGrid, find
the alias in the logs and specify it in a column definition with the help of
:table_alias
.
# encoding: utf-8 class TwoAssociationsController < ApplicationController def index @projects_grid = initialize_grid(Project) end end
<%= grid(@projects_grid, show_filters: :always) do |g|
g.column name: 'ID', attribute: 'id', filter: false
g.column name: 'Project Name', attribute: 'name'
g.column name: 'Customer company', attribute: 'name', assoc: :customer
g.column name: 'Supplier company', attribute: 'name', assoc: :supplier, table_alias: 'suppliers_projects'
end -%>
.well %h2= current_page_title %p When two associations referring to the same model are joined, ActiveRecord uses a table alias for one of these joins. To make it work with WiceGrid, find the alias in the logs and specify it in a column definition with the help of %code :table_alias \. = show_code = render 'grid'
ID | Project Name | Customer company | Supplier company | |
---|---|---|---|---|
1-3 / 3 | ||||
4 | Ultimate Website | MNU | Coders Unlimited | |
5 | Super Game | MNU | Shift-Command-4 Limited | |
6 | Divine Firmware | SkyNet | Coders Unlimited |