How to do a ransack search on has_one association and sort by it's existance?
Asked Answered
P

0

7

I have two models with has_one and belongs_to associations. I want to sort the model with has_one depending on whether the associated object exists.

I can currently sort for example by associated object field.

Here is the simplified code:

class A < ActiveRecord::Base
  belongs_to :B 
end

class B < ActiveRecord::Base
  has_one :B
end

q = A.all.search(params[:q])
as = q.result.includes(:b)

I have tried:

sort_link @q, :b_id_present
sort_link @q, :b_present

sort_link @q, :b_id_null
sort_link @q, :b_null
Pitcher answered 1/7, 2015 at 9:9 Comment(1)
Did you solve it?Bidden

© 2022 - 2024 — McMap. All rights reserved.