Right now I’m programming a plugin for the project managment app Redmine.
And since I’m new to Rails, I have a question about a query.
Redmine provides me with an Issue model. In my plugin I’m defining an additional IssueRates model, which has the following associations:
class IssueRates < ActiveRecord::Base
unloadable
belongs_to :issue,
...
However, I don’t want to change the standard Issue model to have a has_one association, to keep the redmine code as clean as possible.
But now I need a query like this:
project_issues=Issue.where(:project_id => some_id)
project_issues.each do |i|
puts i.IssueRates.amount
end
Which obviously doesn’t work, because of the missing association. Is there a way to reverse this association? Because then, I could even use eager loading with .includes(:IssueRates).
If this is not possible, I could still get the IssueRates in a separate query…
I suppose you could do:
It seems like more work than just adding
has_oneto your Issue model.