This is an example of N+1 error in my case:
...
CACHE (0.0ms) SELECT * FROM "departments" WHERE ("departments"."id" = 1)
Rendered _list_actions (26.8ms)
Rendered _list_record (34.9ms)
Rendered _list_record_columns (4.4ms)
CACHE (0.0ms) SELECT * FROM "departments" WHERE ("departments"."id" = 1)
Rendered _list_actions (26.9ms)
Rendered _list_record (33.4ms)
Rendered _list_record_columns (4.3ms)
CACHE (0.0ms) SELECT * FROM "departments" WHERE ("departments"."id" = 1)
...
2010/9/17 Andrey Voronkov <[email protected]>:
> I have model TeachingPlace that belongs to Department and to the
> Lecturer models and has table field called position.
> I want to rid off N+1 SQL requests. There is no N+1 if
> config.columns = [:lecturer, :department, :position]
>
> Person who works with this interface is a department agent so I have
> this two methods:
>
> protected
>
> def before_create_save(record)
> if dept = current_dept_head.department
> record.department_id = dept.id
> end
> end
>
> def conditions_for_collection
> if @dept ||= current_dept_head.department
> {:department_id => @dept.id}
> else
> {:department_id => nil}
> end
> end
>
> As you can guess I do not need to display department field in list or
> anywhere in this interface because the user knows what department he
> represents. But this:
> config.list.columns.exclude :department
> causes N+1 error. Is there any kind of descision of my trouble?
>
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.