Rails, Ransack: How to search HABTM relationship for all matches instead of any
With a custom ransack predicate defined as in my answer to your related question, this should work with a simple change to your markup:
- terms.each do |t|
= check_box_tag 'q[id_has_terms][]', t.id
UPDATE
The :formatter
doesn't do what I thought, and seeing as how the Ransack repo makes not a single mention of "subquery," you may not be able to use it for what you're trying to do, after all. All available options seem to be exhausted, so there would be nothing left to do but monkey patch.
Why not just skip ransack and query the "photos" table as you normally would with active record (or even with the Arel query you now have)? You already know the query works. Is there a specific benefit you hoped to reap from using Ransack?
Ransack sort on count of HABTM or HMT associated records
Given you have your entities queried with the above scope, for example your index query always has:
# controller
@search = Theme.ransack(params[:q])
@themes = @search.result(distinct: true).with_quotes_count
Have a try of:
# model
ransacker :quotes_count_sort do
Arel.sql('quotes_count')
end
And use the name of the sort in sort_link
?
Ransack association search breaking after upgrading rails
I have resolved the issue by monkey patching ActiveRecord AliasTracker.
See my gh issue for the full explanation.
Check if a record has related records through Ransack. Rails
The answer was pretty simple: questions_id_null: false
Related Topics
Create SQL Server Table Based on a User Defined Type
Does Liquibase Support Dry Run
Generate SQL Temp Table of Sequential Dates to Left Outer Join To
Sql: Select Top 3 Records + Sum of Quantity
See SQL from Entityframework with Collection-Like Queries
SQL Query Aggregate May Not Appear in Where Clause
Why Can't I Group by 1 When It's Ok to Order by 1
What Is the Equivalent of Xml Path and Stuff in Linq Lambda Expression (Group_Concat/String_Agg)
Vector (Array) Addition in Postgres
Add a Column That Represents a Concatenation of Two Other Varchar Columns
Printing Django Queryset SQL with ""
T-SQL Select Get All Months Within a Range of Years
How to Implement Total Disjoint Specialization in Database
Db2 Drop Table If Exists Equivalent