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

Lookup Table Wrongly Reordered in HasManyFacet #23

Open
idbentley opened this issue Feb 26, 2019 · 1 comment
Open

Lookup Table Wrongly Reordered in HasManyFacet #23

idbentley opened this issue Feb 26, 2019 · 1 comment

Comments

@idbentley
Copy link

Hi all,

I've been using the system for a while now, and it has been working great for me. However, I've added a new facet, and am running into an issue.

I have 5 relavent models/tables

IndexedWriter
Language
Ethnicity
IndexedWritersEthnicity
IndexedWritersLanguage

IndexedWriter
has_many :languages, :through => :indexed_writers_languages
has_many :ethnicities, :through => :indexed_writers_ethnicities

When I introduce facets for language and ethnicity

class WriterSearch < FortyFacets::FacetSearch
    model 'IndexedWriter' # which model to search for
    facet :ethnicities, name: "Ethnicities"
    facet :languages, name: "Languages"
  end

Languages works perfectly, but throws ERROR: missing FROM-clause entry for table "ethnicities_indexed_writers" when I try the other.

After some debugging I've determined the source of the issue is where the join table gets calculated:

https://github.com/FortySource/forty_facets/blob/master/lib/forty_facets/filter/facet_filter_definition.rb#L132

The sort in this line resolves the join table indexed_writers_languages correctly since 'i' < 'l', but it does resolve the ethnicities join table as ethnicities_indexed_writers. This obviously is wrong, and for my case I can change the line to:

join_name = [base_table.to_sdefinition.association.name.to_s].join('_')

But this change breaks a test.

Please advise!

@idbentley
Copy link
Author

For others in this boat - this lexicagraphic ordering is the rails default, FF is following that convention -- it might be better to read the through table off the model, but this behaves in-line with rails generally.

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

1 participant