0
這裏是我的模型關聯:N + 1檢測到父模型的父
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
寶石提醒我到N + 1個查詢並建議我把它給:
N+1 Query detected
Supplier => [:payment_concept]
Add to your finder: :include => [:payment_concept]
而在我的控制,我已經包括供應商(另一N + 1)的問題,但是當我嘗試包括: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'
理解的,因爲該費用只與供應商的關係,並與它沒有直接真實的概念。
有什麼建議嗎?
這工作,謝謝一堆! – sergserg