rails/activerecord/lib
Joe Van Dyk 4364211b77 Fix documentation for find_or_create_by
The code in the comment fails on concurrent inserts if done inside a transaction. 

The fix is to force a savepoint to run so that if the database raises an unique violation exception. Otherwise, you'll get errors like:

```
   (0.3ms)  BEGIN
  Cart Load (0.5ms)  SELECT  "carts".* FROM "carts"  WHERE "carts"."uuid" = '12345' LIMIT 1

# Another process inserts a cart with uuid of '12345' right now

  SQL (4371.7ms)  INSERT INTO "carts" ("created_at", "updated_at", "uuid") VALUES ('2015-03-21 01:05:07.833231', '2015-03-21 01:05:07.833231', '12345') RETURNING "id"  [["created_at", Sat, 21 Mar 2015 01:05:07 PDT -07:00], ["updated_at", Sat, 21 Mar 2015 01:05:07 PDT -07:00], ["uuid", "12345"]]
PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "carts_uuid_idx1"
DETAIL:  Key (uuid)=(12345) already exists.
: INSERT INTO "carts" ("created_at", "updated_at", "uuid") VALUES ('2015-03-21 01:05:07.833231', '2015-03-21 01:05:07.833231', '12345') RETURNING "id"

# Retrying the find

  Cart Load (0.8ms)  SELECT  "carts".* FROM "carts"  WHERE "carts"."uuid" = '12345' LIMIT 1
PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
: SELECT  "carts".* FROM "carts"  WHERE "carts"."uuid" = '12345' LIMIT 1
   (0.1ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
: SELECT  "carts".* FROM "carts"  WHERE "carts"."uuid" = '12345' LIMIT 1
```
2015-03-21 01:16:13 -07:00
..
active_record Fix documentation for find_or_create_by 2015-03-21 01:16:13 -07:00
rails/generators Add Secure Token Generator 2015-01-11 14:42:54 -05:00
active_record.rb Attempt to provide backwards compatible YAML deserialization 2015-03-10 11:56:45 -06:00