我試圖顯示此發現的輸出 -軌 - 顯示嵌套發現哈希
@test = User.joins(:plans => [:categories => [:project => :presentations]]).where(current_user.id)
這裏是我的輸出循環
<% @test.each do |p| %>
<%= p.plans %>
<% p.plans.each do |d| %>
<%= debug(d) %>
<% d.categories.each do |e| %>
<% e.project.each do |r| %>
<%= debug(r) %>
<% end %>
<% end %>
<% end %>
<% end %>
循環工作,直到它到達時,它拋出項目這個錯誤
undefined method `each' for "#<Project:0x000001033d91c8>":Project
如果我在循環將其更改爲項目它給這個錯誤
undefined method `projects' for #<Plan:0x000001033da320>
在類別級別調試顯示了這個
--- !ruby/object:Category
attributes:
id: 2
name: test
short_name: tst
created_at:
updated_at:
category_id: 2
plan_id: 5
我的關係是這樣的
用戶 的has_many:user_plans 計劃 的has_many:user_plans has_and_belongs_to_many:類 類別 HAS_ONE:項目 has_and_belongs_to_many:計劃 項目 的has_many:演示:依賴=>:DELETE_ALL 介紹 belongs_to的:項目
我需要改變我的發現?
謝謝,亞歷克斯
謝謝,應該是has_many – Alex 2011-01-07 15:48:21