I am trying to to filter some stuff in a RoR index using where and joins.
I have
=>
class Milestone < ApplicationRecord
belongs_to :project
end
and
class Project < ApplicationRecord
has_many :milestones
end
And I am trying to create a list of projects with all those which have their last milestone in a specific year.
I am trying this but it does not seem to work.
@projects_2021 = Project.joins(:milestones).where("milestones.last.date.year = 2021")
Try something like this:
Projects.joins(:milestones).where(milestones: { column_name: "aaa" })