这是我的模型关联:
Expense belongs_to Supplier belongs_to Concept
# For example:
"ADSL Connection and Telephone July 2" > Comcast > Internet
"Water Bill August 20" > PG&E > Water
我正在尝试列出我的所有费用,并同时显示支付给的公司以及它们属于什么概念。
bullet
gem 提醒我注意 N+1 查询并建议我将其包括在内:
N+1 Query detected
Supplier => [:payment_concept]
Add to your finder: :include => [:payment_concept]
在我的控制器中,我已经包含了 Supplier (for another N+1) issue,但是当我尝试包含时,:payment_concept
我收到一个错误,它不是一个可识别的符号:
@expenses = Expense.all(:include => [:supplier, :payment_concept])
# In my view:
.rows
- for expense in @expenses
.item
p.date.lato= expense.date_made
p.supplier.lato= expense.supplier.name
p.payment_concept.lato= expense.supplier.payment_concept.name
p.payment_type.lato= expense.payment_type.name
p.account.lato= expense.account
p.price.lato= number_to_currency(expense.price)
.item-actions
= link_to '<i class="icon-remove"></i>'.html_safe, '#', class: 'small-button'
鉴于费用仅与供应商有关系,而不是直接与它的概念有关系,这是可以理解的。
有什么建议么?