Not sure what you mean about Rails "not supporting real database foreign keys".
1) They are officially supported (as of Rails 4.2, I think) and documented <http://guides.rubyonrails.org/active_record_migrations.html#foreign-keys> in the RailsGuides. 2) It's always been easy to add support via gems like Foreigner <https://github.com/matthuhiggins/foreigner>. I've used foreign keys in every Rails system I've worked on, when I had the option. Cheers, Al On Tue, Jan 5, 2016 at 8:46 AM, <[email protected]> wrote: > Here is one example from production - an order has a fulfillment - the > fulfillment can be deleted if it is not 'shipped', very roughly: > > # update > transaction do > fulfillment.status = 'shipped' > fulfillment.save! > StockMovement.new(fulfillment).save > end > > # delete > transaction do > fulfillment.destroy # validates that fulfillment.status = 'unshipped' > end > > Since StockMovements are not real foreign keys, nothing prevents the > fulfillment from being deleted by a dyno handling a delete request even if > another dyno has already created stock_movements since it's validating with > stale data. > > This is just one of a number of cases of an otherwise very normal > transactional process breaking since Rails does validation and relational > logic on the ruby level (not supporting real database foreign keys) - which > means pessimistic locking or isolation level serializable are a must. > > > On Monday, January 4, 2016 at 8:34:03 PM UTC+7, Xavier Noria wrote: >> >> On Sun, Jan 3, 2016 at 1:19 PM, <[email protected]> wrote: >> >> Unfortunately optimistic locking simply does not provide any real >>> guarantees once you have scaled past a single dyno >>> >> >> Can you elaborate? >> >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" 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]. > Visit this group at https://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" 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]. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
