Well, I have a model with a has_many association:
class Foo < ApplicationRecord
has_many :bars
end
Now, I know that if I call foo.bars it loads all the bars where foo_id is foo.id, right? But I would like to override it, so that I could load bars based on other params..
This answer kinda teaches how to override the << (value) method. But yet, I don't know how to apply it in my case.
How could I do that?? Something like this:
class Foo < ApplicationRecord
has_many :bars do
def bars
self.owner = Bar.where(date: foo.date) #just an example
end
end
end
???