This commit is contained in:
1 parent
e54f927149
commit
e18ca373eb
8 files changed
+2
-140
No files matched your search
@@ -31,7 +31,6 @@ class Collection < ApplicationRecord
|
||||
|
||||
has_many :collection_items, dependent: :delete_all
|
||||
has_many :accepted_collection_items, -> { accepted }, class_name: 'CollectionItem', inverse_of: :collection # rubocop:disable Rails/HasManyOrHasOneDependent
|
||||
has_many :top_items, -> { top_items }, class_name: 'CollectionItem', inverse_of: :collection # rubocop:disable Rails/HasManyOrHasOneDependent
|
||||
has_many :collection_reports, dependent: :delete_all
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
@@ -47,15 +47,6 @@ class CollectionItem < ApplicationRecord
|
||||
scope :local, -> { joins(:collection).merge(Collection.local) }
|
||||
scope :accepted_partial, ->(account) { joins(:account).merge(Account.local).accepted.where(uri: nil, account_id: account.id) }
|
||||
scope :pending_or_accepted, -> { where(state: [:pending, :accepted]) }
|
||||
scope :top_items, lambda { |limit = 4|
|
||||
subquery = where('collection_items.collection_id = collections.id')
|
||||
.accepted.ordered.limit(limit)
|
||||
.arel.lateral('top_items')
|
||||
collection_query = Collection
|
||||
.select('top_items.*')
|
||||
.from([Collection.arel_table, subquery])
|
||||
from(collection_query, 'collection_items')
|
||||
}
|
||||
|
||||
def with_local_account?
|
||||
account&.local?
|
||||
|
||||
Reference in new issue
Block a user