【发布时间】:2011-01-07 15:35:40
【问题描述】:
我正在尝试显示此查找的输出 -
@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 :categories 类别 has_one : 项目 has_and_belongs_to_many:计划 项目 has_many :presentations, :dependent => :delete_all 介绍 属于_to:项目
我需要更改我的发现吗?
谢谢,亚历克斯
【问题讨论】:
标签: ruby-on-rails activerecord