I have a set of objects through ActiveRecord, and need to iterate through them to ID a set of conditions.
def get_smith_listings
Listing.joins(:spec).where('specs.broker ilike ?', '%smith%')
end
@listings = Listings.all #actually a built query
@listings.sort_by { |item| item.get_smith_listings? ? 0 : 1 }
=> EXPLAIN for: SELECT "listings".* FROM "listings" INNER JOIN "specs" ON "specs"."listing_id" = "listings"."id" WHERE (specs.agent ilike '%smith%')
QUERY PLAN
--------------------------------------------------------------------------------------
Nested Loop (cost=0.28..848.56 rows=1 width=668)
-> Seq Scan on specs (cost=0.00..840.25 rows=1 width=4)
Filter: ((agent)::text ~~* '%smith%'::text)
-> Index Scan using listings_pkey on listings (cost=0.28..8.30 rows=1 width=668)
Index Cond: (id = specs.listing_id)
(the nature of the question has changed slightly as I've zeroed in on the method required)
I'm having trouble structuring this in a way that a) gets my method recognized (new to helpers) and sets up the query to sort using the boolean.
UPDATE: For this seeking clarification, this is the direction I'm trying to take on this problem: https://www.mateoclarke.com/blog/2015/10/14/what-i-learned-boolean-ruby/