Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- controller do
- def scoped_collection
- sql = <<-SQL.strip_heredoc
- LEFT JOIN lots on audits.auditable_id = lots.id AND audits.auditable_type = 'Lots::Base'
- LEFT JOIN bills on audits.auditable_id = bills.id AND audits.auditable_type = 'Bill'
- UNION ALL
- SELECT * FROM audits
- LEFT JOIN lots on audits.associated_id = lots.id AND audits.associated_type = 'Lots::Base'
- LEFT JOIN bills on audits.associated_id = bills.id AND audits.associated_type = 'Bill'
- SQL
- Audit
- .joins(sql)
- .where("lots.id is not null or (bills.id is not null and bills.state != 'hidden')")
- .reorder(:created_at)
- .limit(LIMIT)
- .preload(:auditable)
- .preload(:user)
- end
- end
- PG::SyntaxError: ERROR: each UNION query must have the same number of columns
- LINE 4: SELECT * FROM audits
- ^
- : SELECT "audits".* FROM "audits" LEFT JOIN lots on audits.auditable_id = lots.id AND audits.auditable_type = 'Lots::Base'
- LEFT JOIN bills on audits.auditable_id = bills.id AND audits.auditable_type = 'Bill'
- UNION ALL
- SELECT * FROM audits
- LEFT JOIN lots on audits.associated_id = lots.id AND audits.associated_type = 'Lots::Base'
- LEFT JOIN bills on audits.associated_id = bills.id AND audits.associated_type = 'Bill' WHERE (lots.id is not null or (bills.id is not null and bills.state != 'hidden')) ORDER BY "audits"."id" desc LIMIT 30 OFFSET 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement