diff options
| author | Teddy Wing | 2017-12-12 17:01:49 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-12-12 17:01:49 +0100 | 
| commit | df13a9b7b26b568b5edcea590a2e867d26580d22 (patch) | |
| tree | 6e3f668b8829e636cfb19bbbb493114977693333 /app/models/referential.rb | |
| parent | 55b995531b2504792dfa1b0314b5cc5b55a775ac (diff) | |
| download | chouette-core-df13a9b7b26b568b5edcea590a2e867d26580d22.tar.bz2 | |
Referential: Lock table on :update
We had been locking the `referentials` table on :create, but we also
want to handle :update. Paired on this with Johan.
When I used:
    referential_2.metadatas << metadata_2
the referential was saved. To add the metadata without automatically
saving the referential + metadata, Johan suggested using the nested
attribute method:
    referential_2.metadatas_attributes = [metadata_2.attributes]
This allows us to add the metadata and still use the `#save` method to
lock the table.
Also change the callback from `before_validation` to `before_save`
because
    before_validation :lock_table, on: [:create, :update]
didn't work. That caused an error in our `expect`, as the `be_valid`
triggered the lock callback. To enable the callback on both :create and
:update, use a `before_save` instead.
Refs #5024
Diffstat (limited to 'app/models/referential.rb')
| -rw-r--r-- | app/models/referential.rb | 2 | 
1 files changed, 1 insertions, 1 deletions
| diff --git a/app/models/referential.rb b/app/models/referential.rb index b44bb15c6..6cdab8fb7 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -210,7 +210,7 @@ class Referential < ActiveRecord::Base    # Lock the `referentials` table to prevent duplicate referentials from being    # created simultaneously in separate transactions. This must be the last hook    # to minimise the duration of the lock. -  before_validation :lock_table, on: :create +  before_save :lock_table, on: [:create, :update]    before_create :create_schema    after_create :clone_schema, if: :created_from | 
