Class: FriendlyId::ActiveRecordAdapter::Relation::Find

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/friendly_id/active_record_adapter/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, ids) ⇒ Find

Returns a new instance of Find.



16
17
18
19
# File 'lib/friendly_id/active_record_adapter/relation.rb', line 16

def initialize(relation, ids)
  @relation = relation
  @ids = ids
end

Instance Attribute Details

#idsObject (readonly) Also known as: id

Returns the value of attribute ids.



9
10
11
# File 'lib/friendly_id/active_record_adapter/relation.rb', line 9

def ids
  @ids
end

#relationObject (readonly)

Returns the value of attribute relation.



8
9
10
# File 'lib/friendly_id/active_record_adapter/relation.rb', line 8

def relation
  @relation
end

Instance Method Details

#find_oneObject



21
22
23
24
25
26
27
28
29
# File 'lib/friendly_id/active_record_adapter/relation.rb', line 21

def find_one
  if fc.cache_column?
    find_one_with_cached_slug
  elsif fc.use_slugs?
    find_one_with_slug
  else
    find_one_without_slug
  end
end

#find_someObject



31
32
33
34
35
36
37
38
39
# File 'lib/friendly_id/active_record_adapter/relation.rb', line 31

def find_some
  ids = @ids.compact.uniq.map {|id| id.respond_to?(:friendly_id_config) ? id.id.to_i : id}
  friendly_ids, unfriendly_ids = ids.partition {|id| id.friendly_id?}
  return if friendly_ids.empty?
  records = friendly_records(friendly_ids, unfriendly_ids).each do |record|
    record.friendly_id_status.name = ids
  end
  validate_expected_size!(ids, records)
end