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