2010-06-02 88 views
0

現在。我有一個問題,我希望有人來幫我解決這個問題,該日誌的問題,如在文本軌質疑沒有找到結果

>> Department.find(EmeReference.find(:all,:select =>:ref_config_id,:conditions=>"emergency_id = 1")) 
ActiveRecord::RecordNotFound: Couldn't find Department with ID=0 
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1591:in `find_one' 
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1574:in `find_from_ids_without_cache' 
from (__DELEGATION__):2:in `__send__' 
from (__DELEGATION__):2:in `find_from_ids_without_cache' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:158:in `find_from_keys' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/primary_key.rb:31:in `miss' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:66:in `hit_or_miss' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/accessor.rb:17:in `call' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/accessor.rb:17:in `fetch' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/accessor.rb:29:in `get' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:65:in `hit_or_miss' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:18:in `perform' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/primary_key.rb:17:in `perform' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:7:in `perform' 
from /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/finders.rb:29:in `find_from_ids' 
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:616:in `find' 
from (irb):135 

這是個問題!感謝你並致以真誠的問候!

+0

請注意,該空間應該在句點,逗號等之後,而不是之前。 – 2010-06-02 17:00:26

+0

對不起,我不知道你是什麼意思?你能清楚地說清楚嗎?謝謝! – 2010-06-03 01:22:45

回答

4

Rails自己管理模型之間的關係。你不需要像這樣嵌套呼叫。

EmeReference.find_by_emergency_id(1).department 

這將emergency_id=1檢索EmeReference對象。因爲你應該已經定義了該模型和Department之間的關係,所以rails爲這個第二個模型名稱創建了一個虛擬方法,允許你獲取它。

你應該看看這兩個指南。 Active Record AssociationsActive Record Query Interface

+0

謝謝你的幫助,看了這兩篇指南後,我清楚地理解了軌道模型的關係。 – 2010-06-02 06:57:18