Advertisement
Guest User

Untitled

a guest
Oct 6th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.57 KB | None | 0 0
  1. controller do
  2.     def scoped_collection
  3.       sql = <<-SQL.strip_heredoc
  4.         LEFT JOIN lots on audits.auditable_id = lots.id AND audits.auditable_type = 'Lots::Base'
  5.         LEFT JOIN bills on audits.auditable_id = bills.id AND audits.auditable_type = 'Bill'
  6.         UNION
  7.         SELECT audits.*, lots.*, bills.* FROM audits
  8.         LEFT JOIN lots on audits.associated_id = lots.id AND audits.associated_type = 'Lots::Base'
  9.         LEFT JOIN bills on audits.associated_id = bills.id AND audits.associated_type = 'Bill'
  10.       SQL
  11.  
  12.       Audit
  13.         .select('audits.*, lots.*, bills.*')
  14.         .joins(sql)
  15.         # .where("lots.id is not null or (bills.id is not null and bills.state != 'hidden')")
  16.         # .order('order by id, id, id')
  17.         # .reorder(:created_at)
  18.         # .limit(LIMIT)
  19.         # .preload(:auditable)
  20.         # .preload(:user)
  21.     end
  22.  
  23. PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "audits"
  24. LINE 6: ...s.id AND audits.associated_type = 'Bill' ORDER BY "audits"."...
  25.                                                             ^
  26. : SELECT  audits.*, lots.*, bills.* FROM "audits" LEFT JOIN lots on audits.auditable_id = lots.id AND audits.auditable_type = 'Lots::Base'
  27. LEFT JOIN bills on audits.auditable_id = bills.id AND audits.auditable_type = 'Bill'
  28. UNION
  29. SELECT audits.*, lots.*, bills.* FROM audits
  30. LEFT JOIN lots on audits.associated_id = lots.id AND audits.associated_type = 'Lots::Base'
  31. LEFT JOIN bills on audits.associated_id = bills.id AND audits.associated_type = 'Bill' ORDER BY "audits"."id" desc LIMIT 30 OFFSET 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement