On Domingo, 5 de febrero de 2012 22:32:04 Tin Vo escribió:
> I have another problem related to this problem. My model has another
> association that is being blocked from working correctly.
> In particular, I defined these in the controller for field searching, but
> it's not giving me correct results when searching on the 2nd association.
>
> config.columns[:course_languages].includes = {:course_languages =>
> {:location_language => :language}}
> config.columns[:course_languages].search_ui = :string
> config.columns[:course_languages].search_sql = 'languages.description'
> config.columns[:course_instruction_languages].includes = {
>
> :course_instruction_languages => :language }
>
> config.columns[:course_instruction_languages].search_ui = :string
> config.columns[:course_instruction_languages].search_sql =
> 'languages.iso_code'
>
>
> Searching on :course_languages gives the correct result, but always fail
> when searching on :course_instruction_languages
>
> ActiveScaffold seems to be using the first association when it supposed to
> be the second one. If I disabled the first includes by commenting it out,
> then searching on the :course_instruction_languages association works
> correctly.
>
> What am I doing wrong?
When you need to join a table twice, ActiveRecord generates an alias for the
second join, look at generated sql and change search_sql to use the alias
instead of languages
>
> -Tin
>
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]] On Behalf Of Sergio Cambra
> > Sent: Tuesday, January 24, 2012 2:27 AM
> > To: [email protected]
> > Subject: Re: Stuck with field searching of association
> >
> > 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.descriptio
> >
> > > > n",
> > > >
> > > > > > > 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.
--
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.