【发布时间】:2014-03-14 15:29:52
【问题描述】:
我有四个模型
class Votation
belongs_to :quorum
def calc
return self.quorum.calc
end
end
class Quorum
has_one :votation
...
end
class NewQuorum < Quorum
def calc
do stuff and call
self.votation.attribute_a
end
end
class OldQuorum < Quorum
def calc
do stuff and call
self.votation.attribute_b
end
end
我已将投票加载到 @votation 对象中,并急切地加载了关联的 Quorum。
问题是,当我调用@votation.calc 时,ActiveRecord 执行 SQL 选择以再次加载投票,例如,当它必须执行 self.votation.attribute_a 时。
SELECT "votations".* FROM "votations" WHERE "votations"."quorum_id" = $1
我怎样才能避免这个选择被执行?
【问题讨论】:
标签: ruby-on-rails activerecord belongs-to has-one