ruby on rails - named_scope + average is causing the table to be specified more then once in the sql query run on postgresql -
I have such a designated scope ...
named_scope: gender, lambda {| Gender | {: Johns = & gt; {: Survey_session = & gt; : Profile} ,: conditions = & gt; {: Survey_session = & gt; {: Profile = & gt; {: Gender = & gt; Gender}}}}}
And when I call it, everything works fine.
I also have this mediocre method which I call ...
Answer.average (:; {survey_session = & gt; profiles}: ratings , = & Gt include group = & gt; "profiles.career")
whatever
answer-gender ('m'). Average (: Rating ;: Include = & gt; {: survey_session = & gt ;: Profile} ,: Group = & gt; "profiles.career")
I find ...
ActiveRecord :: StatementInvalid: PGError: Error: Select "AVG_RATING" as the AVG_RATING ("Answer" .rating), "North" as the profiles.career profiles_career joins the external "survey_sessions" From: The table name "Profile" was mentioned at the time of "survey_sessions_answers" .id = "Answer" survey_sessions_answers .survey_session_id Left External "Profile" on "Profile" .id = "survey_sessions_answers" .profile_id Join Insider "survey_sessions" on "Survey_sessions" .id = "n "" Profile "on" Profile ".id =" survey_sessions ".profile_id Where (" Profile "." Gender "= E'm ') Group by profiles.career
It is a little hard to read, but I say that I am including the table profile twice.
If I just want to get involved with the average, but this is not really practical because the average is actually being called inside a method that the scod passes. So there is some time to be called together with each other by gender or average and if any profile was missing it would not work.
So either I know how to fix this obvious bug in the rail or a way to find out which scope on an ActiveRecord :: NamedScope :: Scope object Was implemented so that I can see if they have been implemented and if not included in the average.
After the text "itemprop =" text ">
looks like ActiveRecord is causing some bad SQL:
< Select the code> AVG_RATING as the average ("answer" .rating), include profiles.career "answer" left to the left "survey_sessions" on "survey_sessions_answers" .id = "answer" from survey_sessions_answers as profiles_career .survey_session_id Left External Join "Profile" on "Profile" .id = "survey_sessions_answers" .profile_id Join Insiders "Survey_sessions" on "Survey_sessions" .id = "Answer" .survey_session_id Join "Internal Profile" on "Prof Il ".id =" survey_sessions ".profile_id Where (" profiles "." Gender "= E'm '), by profiles.career, group
It is possible that the parts of receiving this estimate As the left adds, and internally involved as part of obtaining criteria: it will not be invalid (only disabled) if it provides nicknames in those tables, but it is not. Is there a way to specify another name from your app?
Comments
Post a Comment