Last active
January 16, 2018 17:44
-
-
Save charly/6c2311abdcfd386d35f5381fe3b74350 to your computer and use it in GitHub Desktop.
How to join associated models of a PgSearch Document to apply dynamic filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PgSearch::Document | |
belongs_to :article, -> {where("searchable_type = 'Article'")}, | |
foreign_key: 'searchable_id' | |
belongs_to :info, -> {where("searchable_type = 'Info'")}, | |
foreign_key: 'searchable_id' | |
end | |
@searched = PgSearch.multisearch(@query). | |
with_pg_search_highlight. | |
includes(:searchable). | |
left_outer_joins(:info, :article). | |
where("infos.lang = :lang OR articles.lang= :lang", lang: I18n.locale) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment