Module: FriendlyId::History::FinderMethods

Includes:
FinderMethods
Defined in:
lib/friendly_id/history.rb

Instance Method Summary collapse

Instance Method Details

#exists_by_friendly_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/friendly_id/history.rb', line 85

def exists_by_friendly_id?(id)
  joins(:slugs, :translations).where(translation_class.arel_table[friendly_id_config.query_field].eq(id)).exists? || joins(:slugs).where(slug_history_clause(id)).exists?
end

#first_by_friendly_id(id) ⇒ Object (private)



91
92
93
94
# File 'lib/friendly_id/history.rb', line 91

def first_by_friendly_id(id)
  matching_record = where(friendly_id_config.query_field => id).first
  matching_record || slug_table_record(id)
end

#slug_history_clause(id) ⇒ Object (private)



100
101
102
# File 'lib/friendly_id/history.rb', line 100

def slug_history_clause(id)
  Slug.arel_table[:sluggable_type].eq(base_class.to_s).and(Slug.arel_table[:slug].eq(id)).and(Slug.arel_table[:locale].eq(::Globalize.locale))
end

#slug_table_record(id) ⇒ Object (private)



96
97
98
# File 'lib/friendly_id/history.rb', line 96

def slug_table_record(id)
  select(quoted_table_name + '.*').joins(:slugs).where(slug_history_clause(id)).order(Slug.arel_table[:id].desc).first
end