我有一个seat对象,该car对象具有一个owner具有a 的对象name。我想同时显示 thecar brand和car' owners name。如何在一个查询中执行此操作?
例如:
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
我会注意到这是一个非常人为的例子来简化我的问题。我连续数千次这样做,因此需要更高的效率。