active_record_upsert
active_record_upsert copied to clipboard
ActiveRecord::Base.upsert should return record instead of boolean when validation fails
In ActiveRecord both Model.create
and Model.update
always return the record (or a collection of records). Unfortunately Model.upsert
only returns the record when validations pass. When they fail it returns false
.
This breaks my expectations on how the API behaves (assuming it mimics ActiveRecord).
While this is an easy thing to change, it's a still major change in terms of the behavior. Code that relies on false
as the return value will inevitably break once it returns the record.
This is a feature which could be created, and named, and a major version introduced.