ruby on rails - N+1 detected on parent of parent model -


here model associations:

expense belongs_to supplier belongs_to concept  # example: "adsl connection , telephone july 2" > comcast > internet "water bill august 20" > pg&e > water 

i'm trying list of expenses, , show both company it's paid to, , concept belong to.

the bullet gem alerting me n+1 query , recommend include it:

n+1 query detected   supplier => [:payment_concept]   add finder: :include => [:payment_concept] 

and in controller, included supplier (for n+1) issue, when try include :payment_concept error it's not recognized symbol:

@expenses = expense.all(:include => [:supplier, :payment_concept])  # in view: .rows   - 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' 

understandable given expense has relationship supplier, , not directly it's concept.

any suggestions?

did try this?

 @expenses = expense.all(:include => [:supplier => :payment_concept]) 

edit:

for clarification, since concept belongs supplier (which belongs expenses), need use hash relationship in includes statement.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -