Module: Familia::Features::ExternalIdentifier::ModelClassMethods
- Defined in:
- lib/familia/features/external_identifier.rb
Overview
ExternalIdentifier::ModelClassMethods
Instance Method Summary collapse
-
#find_by_extid(extid) ⇒ Object?
Find an object by its external identifier.
Instance Method Details
#find_by_extid(extid) ⇒ Object?
Find an object by its external identifier
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/familia/features/external_identifier.rb', line 159 def find_by_extid(extid) return nil if extid.to_s.empty? if Familia.debug? reference = caller(1..1).first Familia.trace :FIND_BY_EXTID, nil, extid, reference end # Look up the primary ID from the external ID mapping primary_id = extid_lookup[extid] return nil if primary_id.nil? # Find the object by its primary ID find_by_id(primary_id) rescue Familia::NotFound # If the object was deleted but mapping wasn't cleaned up # we could autoclean here, as long as we log it. # extid_lookup.remove_field(extid) nil end |