Class: UnionOf::ReadonlyAssociation

Inherits:
ActiveRecord::Associations::CollectionAssociation
  • Object
show all
Defined in:
lib/union_of/readonly_association.rb

Direct Known Subclasses

Association

Constant Summary collapse

MUTATION_METHODS =
i[
  writer ids_writer
  insert_record build_record
  destroy_all delete_all delete_records
  update_all concat_records
]

Instance Method Summary collapse

Instance Method Details

#count_recordsObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/union_of/readonly_association.rb', line 29

def count_records
  count = scope.count(:all)

  if count.zero?
    target.select!(&:new_record?)
    loaded!
  end

  [association_scope.limit_value, count].compact.min
end

#readerObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/union_of/readonly_association.rb', line 18

def reader
  ensure_klass_exists!

  if stale_target?
    reload
  end

  @proxy ||= UnionOf::ReadonlyAssociationProxy.create(klass, self)
  @proxy.reset_scope
end