我有一个拥有许多商店的 Account 类。在 Store 类中,有一个例程返回该帐户的所有其他商店:
def other_stores
if account then
account.stores.find(:all,:conditions=>"id != "+id.to_s)
else
[]
end
end
当我在我的 as_json 例程中包含 :other_stores 然后引用它时,我固定一个 cpu 并挂起。我假设它是 other_stores 中的无限递归。有任何想法吗?有什么办法可以停止递归?
Ruby 1.9.2-p136,Rails 3.0.3