I have two models with belongs_to and has_many relationship. BreedCycle has breed_start_date
datetime attribute. What I am trying to do is to order boxes
by newest(last created) breed cycle's breed_start_date
attribute. Long story short, my goal is to write query that pulls out all newest breed_cycles for the boxes and order boxes by breed_cycles.breed_start_date
attribute. Also breed_start_date
can be nil so I need NULLS LAST
option. Any help(link to docs, examples etc.) is greatly appreciated.
class Box < ApplicationRecord
has_many :breed_cycles
end
class BreedCycle < ApplicationRecord
belongs_to :box
end