Subquery in Rails report generation -
I am creating a report in Ruby on Rails application and I understand how to use a subquery I'm struggling. / P>
Every survey has 'survey response' and it is quite easy to retrieve them, although I need a group according to one of those areas, 'jobcod', because I only Want to report one related information to a single jobcode in one line in the report
However, I need to know the component data that makes use of that job code because the reason I need to calculate data such as the media and standard deviation, and know the values like this Need to understand the total yoga.
My thinking is that I get different jobs which are surveyed and then I receive personal responses to each jobcode as a loop through them.
Is this the right way to do or should I follow a different method?
You can use the named area to make groups of reactions easier to achieve: < / P>
named_scope: job_group, lambda {| Job_code | {: Terms = & gt; Put it in your modeled model, and use it like this: job.responses .job_group ('some work code') and you will get an array of responses. You can use: r = job.responses.job_group ('some work codes') R.map (and: total) = & gt; [1, 5, 3, 8]
Alternatively , you can get a quick write in custom SQL, so that the average / average / group gets the sum For such work of attributes, going through the rail can lead to significant gaps.
ActiveRecord :: Base.connection.execute ("custom SQL here")
Comments
Post a Comment