active_record_upsert icon indicating copy to clipboard operation
active_record_upsert copied to clipboard

ActiveRecord::Base.upsert should return record instead of boolean when validation fails

Open benedikt opened this issue 7 years ago • 1 comments

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.

benedikt avatar Feb 14 '18 14:02 benedikt

This is a feature which could be created, and named, and a major version introduced.

olleolleolle avatar Dec 21 '20 12:12 olleolleolle