lib/ensurance.rb in ensurance-0.1.14 vs lib/ensurance.rb in ensurance-0.1.15
- old
+ new
@@ -39,10 +39,11 @@
if thing.is_a?(Hash)
value = thing.fetch(ensure_field.to_sym, nil) || thing.fetch(ensure_field.to_s, nil)
end
if ensure_field.to_sym == :id
begin
- record = find(value)
+ # Always return the most recent record that matches
+ record = where(ensure_field => value).order(created_at: :desc).first
rescue ActiveRecord::RecordNotFound
nil
end
else
record = find_by(ensure_field => value) if value.present? && !value.is_a?(Hash)