Colin,
Below condition is that it takes only from qa-reports, i need to
display agency details which is not in the qa-reports,
i.e : i need to display details + agency details where agency_id which
is not in qa-reports
same like union function in submitted_reports function
:union=>“SELECT DISTINCT * FROM agencies a where a.id not in
(select agency_id from qareports)”
attributes like locked=‘0’ are just only the attributes
actual query:
SELECT qareports.id AS t0_r0, qareports.agency_id AS t0_r1,
qareports.user_id AS t0_r2, qareports.incident_total AS t0_r3,
qareports.incident_clinical AS t0_r4,
qareports.medication_error AS t0_r5,
qareports.attendance_problem AS t0_r6,
qareports.attitude_problem AS t0_r7, qareports.incident_other
AS t0_r8, qareports.facility_actions AS t0_r9,
qareports.dnr_facilities AS t0_r10, qareports.dnr_actions AS
t0_r11, qareports.formal_reports AS t0_r12,
qareports.formal_reports_details AS t0_r13,
qareports.reporting_period AS t0_r14, qareports.locked AS
t0_r15, qareports.created_at AS t0_r16, qareports.updated_at
AS t0_r17, qareports.az_contract_id AS t0_r18,
qareports.az_admin_visits AS t0_r19, agencies.id AS t1_r0,
agencies.name AS t1_r1, agencies.parent_id AS t1_r2,
agencies.address1 AS t1_r3, agencies.address2 AS t1_r4,
agencies.city AS t1_r5, agencies.state_id AS t1_r6,
agencies.zip1 AS t1_r7, agencies.zip2 AS t1_r8,
agencies.phone AS t1_r9, agencies.fax AS t1_r10,
agencies.web_site AS t1_r11, agencies.status AS t1_r12,
agencies.notes AS t1_r13, agencies.deleted AS t1_r14,
agencies.deleted_at AS t1_r15, agencies.created_at AS t1_r16,
agencies.updated_at AS t1_r17,
agencies.authorized_signator_firstname AS t1_r18,
agencies.authorized_signator_lastname AS t1_r19,
agencies.authorized_signator_title AS t1_r20,
agencies.authorized_signator_email AS t1_r21,
agencies.authorized_signator_phone AS t1_r22,
agencies.coordinator_id AS t1_r23, agencies.external_id AS
t1_r24 FROM qareports LEFT OUTER JOIN agencies ON agencies.id =
qareports.agency_id WHERE (((locked = ‘1’) AND (reporting_period >=
‘2009-08-01’ and reporting_period <= ‘2010-08-31’)) AND (agency_id=
‘96’)) ORDER BY reporting_period, agencies.name
- i need to use this query by union function
SELECT DISTINCT * FROM agencies a where a.id not in (select agency_id
from qareports)
class Qareport < ActiveRecord::Base
belongs_to :agency
belongs_to :user
Query to get unsubmitted reports
for a given agency
First parameter is the 0-Unlocked(Unsubmitted) , 1-Locked
(Submitted)
named_scope :submitted_reports, lambda {|*args|
{
:conditions => [‘locked = ?’, (args.first || submited_status)],
:union=>“SELECT DISTINCT * FROM agencies a where a.id not in
(select agency_id from qareports)”
}
}