Module: Familia::Features::ExternalIdentifier::ModelInstanceMethods
- Defined in:
- lib/familia/features/external_identifier.rb
Overview
Instance methods for external identifier management
Instance Method Summary collapse
-
#save(update_expiration: true) ⇒ Boolean
Override save to update extid_lookup mapping.
-
#save_if_not_exists(update_expiration: true) ⇒ Boolean
Override save_if_not_exists to update extid_lookup mapping.
Instance Method Details
#save(update_expiration: true) ⇒ Boolean
Override save to update extid_lookup mapping
This ensures the extid_lookup index is populated during save operations rather than during object initialization, preventing unwanted database writes when calling .new()
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/familia/features/external_identifier.rb', line 166 def save(update_expiration: true) result = super # Update extid_lookup mapping after successful save if result && respond_to?(:extid) && respond_to?(:identifier) current_extid = extid # Triggers lazy generation if needed if current_extid && identifier self.class.extid_lookup[current_extid] = identifier end end result end |
#save_if_not_exists(update_expiration: true) ⇒ Boolean
Override save_if_not_exists to update extid_lookup mapping
This ensures the extid_lookup index is populated during create operations which use save_if_not_exists instead of save.
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/familia/features/external_identifier.rb', line 188 def save_if_not_exists(update_expiration: true) result = super # Update extid_lookup mapping after successful save if result && respond_to?(:extid) && respond_to?(:identifier) current_extid = extid # Triggers lazy generation if needed if current_extid && identifier self.class.extid_lookup[current_extid] = identifier end end result end |