about summary refs log tree commit diff
path: root/app/models/collection_item.rb
blob: cecb86534f3b48f900b7bf4a5806279a4d7c35dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true
# == Schema Information
#
# Table name: collection_items
#
#  id         :bigint(8)        not null, primary key
#  account_id :bigint(8)
#  uri        :string           not null
#  processed  :boolean          default(FALSE), not null
#

class CollectionItem < ApplicationRecord
  belongs_to :account, inverse_of: :collection_items, optional: true

  default_scope { order(id: :desc) }
  scope :unprocessed, -> { where(processed: false) }
  scope :joins_on_collection_pages, -> { joins('LEFT OUTER JOIN collection_pages ON collection_pages.account_id = collection_items.account_id') }
  scope :inactive, -> { joins_on_collection_pages.where('collection_pages.account_id IS NULL') }
  scope :active, -> { joins_on_collection_pages.where('collection_pages.account_id IS NOT NULL') }
end