Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 associations to the same table (nested associations) #325

Open
Obi-TOB opened this issue Sep 1, 2016 · 2 comments
Open

2 associations to the same table (nested associations) #325

Obi-TOB opened this issue Sep 1, 2016 · 2 comments

Comments

@Obi-TOB
Copy link

Obi-TOB commented Sep 1, 2016

Hi,

I would really require some input :)

I have a model (a soccer match) with two associated teams (home_team, guest_team both of class Team). Both of them have translated names in an associated model Team::Translations (globalize3).

The soccer match has other associations as well (sport with its associated translations in Sport::Translations, competition with Competition::Translations, ...). These are working find with Wice_Grid. If I use only one of the associated teams elements are displayed as expected.

However if I have both home_team and guest_team assocations in Wice_Grid the entries of Team::Translations are only displayed in the column where they first occur.

So I think that AR gets confused as both nested associations (the translations) have the same model (and table_name) Team::Translation (team_translations).

So of course I tried to used the table_alias as described in the docs (which works fine as long as the attributes are directly in the Team association (home_team or guest_team of model Team). However I don't find a way to put an alias on the nested association (home_team.team_name / guest_team.team_name (both if model Team::Translation).

I have already passed quite a few hours stepping through the WiceGrid code, however, to be honest, the alias is my best guess, however not fully confirmed.

Any thoughts or ideas for workarounds would be highly appreciated.

I attached the definition of the grid. I'm using 3.6.0-pre4 (and tested as well on 3.6.0-pre5). Rails 4.2.5 and Ruby 2.2.5.

  g.column name: 'Sport',  attribute: 'sport_name', assoc: [:sport, :translations], detach_with_id: :id_sport, custom_filter: :auto do |match|
    match.sport.sport_name
  end

  g.column name: 'Competition', assoc: [:competition, :translations], attribute: 'competition_name', detach_with_id: :id_league, custom_filter: :auto do |match|
      match.competition.competition_name
  end

  g.column name: 'Season', assoc: [:season, :translations], attribute: 'season_name', detach_with_id: :id_season, custom_filter: :auto do |match|
    match.season.season_name
  end

  g.column name: 'Details', attribute: 'details', filter:false

  g.column name: 'Home Team', attribute: 'team_name', assoc:  [:home_team, :translations], filter:false do |match|
    match.home_team.team_name
  end

  g.column name: 'Guest Team', attribute: 'team_name', assoc: [:guest_team, :translations], table_alias: 'guest_team', filter:false do |match|
    match.guest_team.team_name
  end
@Obi-TOB
Copy link
Author

Obi-TOB commented Sep 2, 2016

I guess the easiest way to go would probably be to define a CustomViewColumn where I can "hardcode" the alias for the nested association. However I have difficulties to understand, where the value for the table field is actually selected (in the standard ViewColumns).

Could you point me in the right direction?

@leikind
Copy link
Owner

leikind commented Sep 6, 2016

Sorry for this late reply.

WiceGrid does not support aliases for nested associations. An sql view is the only option here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants