# Save method behaviour changed?

**URL:** <https://discuss.rubyonrails.org/t/save-method-behaviour-changed/66505>\
**Category:** rubyonrails-talk\
**Created:** [March 5, 2013, 7:32pm UTC](https://discuss.rubyonrails.org/t/save-method-behaviour-changed/66505 "2013-03-05T19:32:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_B\_Byrne](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@James\_B\_Byrne](https://discuss.rubyonrails.org/u/James_B_Byrne)\
**Post date:** [March 5, 2013, 7:32pm UTC](https://discuss.rubyonrails.org/t/save-method-behaviour-changed/66505/1 "2013-03-05T19:32:18Z")

</div>

I have this code in a working RoR-3.1 app:

# save

---

<div class="post-metadata">

**Author:** ![Tamara\_Temple](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@Tamara\_Temple](https://discuss.rubyonrails.org/u/Tamara_Temple)\
**Post date:** [March 6, 2013, 12:13am UTC](https://discuss.rubyonrails.org/t/save-method-behaviour-changed/66505/2 "2013-03-06T00:13:47Z")

</div>

I don't know the answer to your question, but I'm wondering if you can circumvent the exception altogether by using valid? to see if it's a valid record before attempting the save?

---

<div class="post-metadata">

**Author:** ![James\_B\_Byrne](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@James\_B\_Byrne](https://discuss.rubyonrails.org/u/James_B_Byrne)\
**Post date:** [March 6, 2013, 1:33am UTC](https://discuss.rubyonrails.org/t/save-method-behaviour-changed/66505/3 "2013-03-06T01:33:42Z")

</div>

Rails validation for duplicate records is, to put it bluntly, a joke. The code I wrote is intended to compensate for that fact by using the DBMS as it is intended to be used. Up to the current version of Rails this worked as I intended. Now it does not. I simply want to discover what has changed and how I get around it.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [March 6, 2013, 9:54am UTC](https://discuss.rubyonrails.org/t/save-method-behaviour-changed/66505/4 "2013-03-06T09:54:19Z")

</div>

> I have this code in a working RoR-3.1 app:
> 
> &nbsp;&nbsp;# save &nbsp;&nbsp;# &nbsp;&nbsp;# Override AR save method to catch DBMS specific errors &nbsp;&nbsp;# such as uniqueness constraint violations

Where is this code? in a model, in module that is included into various models, somewhere else?

As an aside recent versions of rails raise ActiveRecord::RecordNotUnique in such cases, although this is a subclass of ActiveRecord::StatementInvalid so shouldn't change behaviour as far as you're concern. You're also changing the signature of save although I don't think that is related to the problem at hand.

Fred

---

<div class="post-metadata">

**Author:** ![James\_B\_Byrne](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@James\_B\_Byrne](https://discuss.rubyonrails.org/u/James_B_Byrne)\
**Post date:** [March 6, 2013, 2:44pm UTC](https://discuss.rubyonrails.org/t/save-method-behaviour-changed/66505/5 "2013-03-06T14:44:53Z")

</div>

It is contained in a model:

class Currency \< ActiveRecord::Base &nbsp;&nbsp;include HLLActiveRow

&nbsp;&nbsp;after\_save( :save\_errors ) . . . &nbsp;&nbsp;# save
