WiceGrid 3.6.0.pre4 examples

2 associations to the same table

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'
    
IDProject NameCustomer companySupplier company
1-3 / 3
4Ultimate WebsiteMNUCoders Unlimited
6Divine FirmwareSkyNetCoders Unlimited
5Super GameMNUShift-Command-4 Limited

Fork me on GitHub