を持つseatオブジェクトを持つcarオブジェクトがownerありますname。car brandとcar's owner'を一緒に表示したいname。1つのクエリでこれを行うにはどうすればよいですか?
例えば:
class Seat < ActiveRecord::Base
belongs_to :car
def description
"I am in a #{car.brand} belonging to #{car.owner.name}"
# --> how do I replace this with one query?
end
end
これは私の質問を単純化するための非常に工夫された例であることに注意してください。私はこれを何千回も続けて行っているので、より効率的なものが必要です。