How do I search ransack in the has_one of an association and sort existance by it?

I have two models with associations has_one

and belongs_to

. I want to sort the model using has_one

depending on whether the associated object exists.

Currently I can sort, for example, by the field of the related object.

Here's a 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

      

+5


source to share





All Articles