On Tue, March 5, 2013 19:13, tamouse mailing lists wrote:
> On Tue, Mar 5, 2013 at 1:32 PM, byrnejb <[email protected]> wrote:
>> I have this code in a working RoR-3.1 app:
>>
>>   # save
>>   #
>>   # Override AR save method to catch DBMS specific errors
>>   # such as uniqueness constraint violations
>>   def save
>>     super
>>     rescue ActiveRecord::StatementInvalid => this_exception
>>       errors.add( currency_code, hll_ar_exception( this_exception )
>> )
>>       false
>>   end
>>
>> In RoR-3.2.12  this no longer works.  Once I pass a save involving a
>> duplicate record it never returns to the calling method.  For
>> example:
>>
>>   def save
>>     super
>>     fail( " die die die " )
>>     rescue ActiveRecord::StatementInvalid => this_exception
>>
>> produces no output and does not throw an exception but in the log
>> file I see
>> this none-the-less:
>>
>> PG::Error: ERROR:  duplicate key value violates unique constraint
>> "idxu_currencies_currency_code"
>> DETAIL:  Key (currency_code)=(JPY) already exists.
>>
>>
>> How do I get the old behaviour back?  Calling save! instead super
>> does not
>> change the outcome.
>
> 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?
>

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.


-- 
***          E-Mail is NOT a SECURE channel          ***
James B. Byrne                mailto:[email protected]
Harte & Lyne Limited          http://www.harte-lyne.ca
9 Brockley Drive              vox: +1 905 561 1241
Hamilton, Ontario             fax: +1 905 561 0757
Canada  L8E 3C3

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to