I am very stuck on this problem: I have next models (it's all from Redmine):
Issue (has_many :journals)
Journal (has_many :details, :class_name => "JournalDetails)
JournalDetails
I want fetch last changing of a state of a issue: date saved in Journal model but for filter only changing state I must join to JournalDetails.
Issue.eager_load(:journals).eager_load(journals: :details)
It's work but journals have all items not only changes of state - and how I can filter only changing of state without additional query I don't know
My next try:
Issue.eager_load({:journals => :details}).where("journal_details.prop_key = 'status_id'")
In this case I don't get issues which has not changes of state.
This should work:
Or, you can merge the scope from the details model: