title: Union all and maintain active record relations?
body: <p>This is my query</p>
  <pre><code>SELECT * FROM (SELECT id as broadcast_id, null as message_id, company_id, title, category, publish_at as created_at, image_file_name, null as is_featured, summary, video_link, file FROM broadcasts
  UNION ALL
  SELECT null, id, company_id, title, 'user_video', created_at, cover_photo_file_name, is_featured, content, video_link, null  FROM `messages` WHERE video_link is not null  and video_link != '')my_table
  ORDER BY created_at DESC LIMIT 15
  </code></pre>
  <p>I want to maintain everything as Broadcast active-record relation.</p>
  <p>I actually got this working using the active record extended gem</p>
  <pre><code>    legacy_broadcasts = Broadcast.select(:id, &quot;null as message_id&quot;, :publish_at, :company_id, :title, :category, :image_file_name, :summary, &quot;null as is_featured&quot;, :file, :video_link, :url)
      user_videos       = Message.select(&quot;null&quot;, :id, :created_at, :company_id, :title, &quot;\&quot;user_video\&quot; as category&quot;, :cover_photo_file_name, :content, :is_featured, &quot;null as file&quot;, :video_link, &quot;null as url&quot;).where('video_link is not null  and video_link != \'\'')
      base              = Broadcast.union_all(legacy_broadcasts, user_videos)
                                   .includes(:company)
                                   .published
                                   .order(publish_at: :desc)
  
      @q                = base.ransack(params[:q])
      @video_broadcasts = base.has_video_link
                              .paginate(
                                page:     page,
                                per_page: 5)
                              .to_a
  
      @broadcasts = @q
                      .result
                      .paginate(
                        page:     page,
                        per_page: 9)
                      .to_a
  </code></pre>
  <p>but I'm not allowed to add the pg gem into prod that is required by the active recorded extended gem unfortunately. Any idea on how I can best accomplish this?</p>