leikind / wice_grid

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

Has many associations in separate lines #263

Closed Obi-TOB closed 8 years ago

Obi-TOB commented 8 years ago

Hi,

I have the following models:

class Barmatch < ActiveRecord::Base
  belongs_to :match
end

and

class Match < ActiveRecord::Base
    has_many :barmatchs
end

I'm trying to show in the grid all Barmatches with the Bar information (one per line), even if no Bar information is available (i.e. LEFT JOIN) with one match / barmatch combination per line.

I used

@match_grid= initialize_grid(Match, include:  [:barmatchs])

This does a left join, however, this gives in the grid all barmatchs in the same line that I can display via

g.column name: 'Match ID from BarMatch', attribute: 'match_id', filter:false, assoc: :barmatchs do |match|
    match.barmatchs.to_sentence
end

I tried as well

@barmatch_grid = initialize_grid(Barmatch, include:  [:match])

which does obviously not help as it does the left join on Barmatch, i.e. I'm loosing all bars without Barmatch.

I'm using Rails 4.2.4, Wice_grid 3.6.0.pre4

Any idea / suitable documentation links how to get the desired result? Would a suitable db view help? Would it help to manipulate the scope? Any further input I could provide?

Best

Obi-TOB commented 8 years ago

I read a bit further in particular Issue 260 and in fact I have a man. -to-many relationship as well (above was for simplification reasons). The point is I need a right join from the matching table "Barmatch" to "Match". I think this is not covered by the association model of ROR. Any idea how to solve this? In particular involving wice_grid?