On Viernes, 17 de Septiembre de 2010 01:29:30 Andrey Voronkov escribió:
> 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)
If you are excluding department column, why is department loaded? Is it used
in some override? In a security check? Anyway you can override
active_scaffold_includes:
def active_scaffold_includes
@active_scaffold_includes ||= [:department]
end
>
> ...
>
> 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?
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--
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.