On Lunes, 23 de enero de 2012 10:33:22 Tin Vo escribió:
> Thank you very much; that works great. However, there's a small hiccup. It
> searches correctly on Courses with the chosen language.description; but the
> result list display excludes other languages.
> For example: course '123' has 2 courses_language: "English" and "French",
> after searching for language.description 'French', the result list shows
> course '123' correctly, but the column 'Course languages' only shows
> 'French' and excludes 'English'.
>
> Is there a way to make it search using the filter but do not exclude the
> filter in the displaying of results?
>
You could set joins_for_collection instead of column includes, disabling eager
loading for that column, although you will get a query for each course. You
will have to write left joins instead of using a hash of symbols.
Maybe you could set active_scaffold_joins without removing column includes, I'm
not sure whether it works:
config.columns[:language].search_sql = 'l.description'
def joins_for_collection
if search_params.present?
'LEFT JOIN languages l ON location_languages.language_id = l.id'
end
end
> -Tin
>
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]] On Behalf Of Sergio Cambra
> > Sent: Monday, January 23, 2012 10:14 AM
> > To: [email protected]
> > Subject: Re: Stuck with field searching of association
> >
> > On Lunes, 23 de enero de 2012 10:00:13 Tin Vo escribió:
> > > Thank you for your help; but I'm getting the error:
> > > ActiveRecord::ConfigurationError (Association named
> > > 'location_language' was not found Please note that for the 'Courses'
> > > table, there's no such association; it has an association called
> > > "course_languages".
> >
> > I understood you that you want to add to course languages table. Change
> > it to:
> > config.columns[:language].includes = {:course_languages =>
> > {:location_language => :language}}
> >
> > > -Tin
> > >
> > > > -----Original Message-----
> > > > From: [email protected]
> > > > [mailto:[email protected]] On Behalf Of Sergio
> > > > Cambra
> > > > Sent: Monday, January 23, 2012 3:04 AM
> > > > To: [email protected]
> > > > Subject: Re: Stuck with field searching of association
> > > >
> > > > On Sábado, 21 de enero de 2012 17:01:46 Tin Vo escribió:
> > > > > Hello,
> > > > >
> > > > > I'm quite new to AS; and I've been scratching my head for
> > > > > too
> >
> > long
> >
> > > > > with this problem. I have the following relation:
> > "course.course_languages.first.location_language.language.description",
> >
> > > > > where "courses" has many "course_languages" belongs to
> > > > > "location_language" belongs to "language"
> > > > >
> > > > > I would like to enable field search on Courses table for
> > > > > column
> > > > > "course_languages" searching on "description" of the
> > > > > "language".
> > > > >
> > > > > Any help is greatly appreciated.
> > > > > -Tin
> > > >
> > > > Set includes and search_sql for langague virtual column
> > > >
> > > > Create virtual column:
> > > > config.columns << :language
> > > > config.columns.exclude :language
> > > > config.field_search.columns << :language
> > > >
> > > > You can exclude from other actions instead of
> >
> > config.columns.exclude
> >
> > > > Also, you should define language in the model to avoid
> > > > exceptions:
> > > > def language
> > > >
> > > > location_language.try(:language).try(:description)
> > > >
> > > > end
> > > >
> > > > Set includes and search_sql:
> > > > config.columns[:language].includes = {:location_language =>
> > :
> > :language}
> > :
> > > > config.columns[:language].search_sql = 'languages.description'
> > > >
> > > > --
> > > > 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.
> >
> > --
> > 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.
--
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.