sequelize/sequelize — pull request #2173 by janmeier (2014-08-22 07:08:33+00:00)
Title: [WIP] Use a transaction internally in findOrCreate

The tests are not passing yet, so this is still WIP, but I'm throwing it up here for a preliminary review :)

The case where the user passes in a transaction was the hardest to handle. We have to use the passed transaction, so other calls on the same transaction cannot be blocked. This means that we have to handle the case where something was inserted after we did a find call. In mysql and sqlite handling the unique error is no problem, but with postgres, a transaction becomes unusable if a unique constraint error is thrown inside it. This means we have to catch the exception and handle it ourselves. This is done by creating a temp. function which returns an empty result set.