aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/locking
Commit message (Collapse)AuthorAgeFilesLines
* Attribute assignment and type casting has nothing to do with columnsSean Griffin2015-01-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's finally finished!!!!!!! The reason the Attributes API was kept private in 4.2 was due to some publicly visible implementation details. It was previously implemented by overloading `columns` and `columns_hash`, to make them return column objects which were modified with the attribute information. This meant that those methods LIED! We didn't change the database schema. We changed the attribute information on the class. That is wrong! It should be the other way around, where schema loading just calls the attributes API for you. And now it does! Yes, this means that there is nothing that happens in automatic schema loading that you couldn't manually do yourself. (There's still some funky cases where we hit the connection adapter that I need to handle, before we can turn off automatic schema detection entirely.) There were a few weird test failures caused by this that had to be fixed. The main source came from the fact that the attribute methods are now defined in terms of `attribute_names`, which has a clause like `return [] unless table_exists?`. I don't *think* this is an issue, since the only place this caused failures were in a fake adapter which didn't override `table_exists?`. Additionally, there were a few cases where tests were failing because a migration was run, but the model was not reloaded. I'm not sure why these started failing from this change, I might need to clear an additional cache in `reload_schema_from_cache`. Again, since this is not normal usage, and it's expected that `reset_column_information` will be called after the table is modified, I don't think it's a problem. Still, test failures that were unrelated to the change are worrying, and I need to dig into them further. Finally, I spent a lot of time debugging issues with the mutex used in `define_attribute_methods`. I think we can just remove that method entirely, and define the attribute methods *manually* in the call to `define_attribute`, which would simplify the code *tremendously*. Ok. now to make this damn thing public, and work on moving it up to Active Model.
* Go through normal where logic in destroy with lockingSean Griffin2015-01-141-6/+2
| | | | | | Building the Arel AST, and manipulating the relation manually like this is prone to errors and breakage as implementation details change from underneath it.
* Properly persist `lock_version` as 0 if the DB has no defaultSean Griffin2015-01-091-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | The reason this bug occured is that we never actually check to see if this column has changed from it's default, since it was never assigned and is not mutable. It appears I was wrong in b301c40224c6d15b539dbcc7485adb44d810f88c, with my statement of "there is no longer a case where a given value would differ from the default, but would not already be marked as changed." However, I chose not to revert the deletion of `initialize_internals_callback` from that commit, as I think a solution closer to where the problem lies is less likely to get erroneously removed. I'm not super happy with this solution, but it mirrors what is being done in `_update_record`, and a fix for one should work for the other. I toyed with the idea of changing the definition of `changed?` on the type to `changed_in_place?`. If we type cast the raw value, it'll break a test about updating not modifying the lock column if nothing else was changed. We could have the definition check if `raw_old_value` is `nil`, but this feels fragile and less intention revealing. It would, however, have the benefit of cleaning up old data that incorrectly persisted as `nil`. Fixes #18422
* Tiny documentation fixes [ci skip]Robin Dupret2014-12-301-1/+1
|
* Go through normal `update_all` logic when updating lock columnsSean Griffin2014-12-261-17/+7
|
* We don't need additional type casting for locking updatesSean Griffin2014-12-261-3/+11
| | | | | | | Part of the larger refactoring to remove type casting from Arel. We can inform it that we already have the right type by wrapping the value in an `Arel::Nodes::Quoted`. This commit can be reverted when we have removed type casting from Arel in Rail 5.1
* Remove the unused second argument to `substitute_at`Sean Griffin2014-11-171-1/+1
| | | | Oh hey, we got to remove some code because of that!
* Stop using instance exec for type decoratorsSean Griffin & Sean Doyle2014-06-271-5/+16
| | | | | | | | We are moving this behavior out to an object that we would like to keep separated from `ActiveRecord::Base`, which means not passing the class object to it. As such, we need to stop using `instance_exec`, and instead close over the subclass on global type decorators that are applied in `Base`.
* add missing `:nodoc:` for recent refactorings. [ci skip]Yves Senn2014-06-241-1/+1
| | | | | | | | | | Adding `# :nodoc:` to the parent `class` / `module` is not going to ignore nested classes or modules. There is a modifier `# :nodoc: all` but sadly the containing class or module will continue to be in the docs. /cc @sgrif
* Don't mess with `column_defaults` when optimistic locking is enabledSean Griffin2014-06-171-10/+23
|
* Remove deprecated method ActiveRecord::Base.quoted_locking_columnAkshay Vishnoi2014-06-101-6/+0
|
* Remove duplicated `@raw_attributes.keys`Sean Griffin2014-06-071-1/+1
| | | | | Reduces the number of things outside of attribute methods that cares about the details of how we store and type cast attributes
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-1/+1
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* [Active Record] Renamed private methods create_record and update_recordPrathamesh Sonpatki2014-02-201-1/+1
| | | | | | This is to ensure that they are not accidentally called by the app code. They are renamed to _create_record and _update_record respectively. Closes #11645
* pass the pk to compile_updateAaron Patterson2013-11-161-1/+4
|
* [ci skip] avoid deprecation warning in sample codesue4452013-10-181-3/+3
| | | | | Account.find(1, lock: true) -> DEPRECATION WARNING: Passing options to #find is deprecated. Please build a scope and then call #find on it.
* Deprecate unused quoted_locking_column method.kennyj2013-09-241-0/+1
|
* Tidy up the "Specified column type for quote_value" changesBen Woosley2013-07-221-1/+1
| | | | | | This includes fixing typos in changelog, removing a deprecated mocha/setup test require, and preferring the `column_for_attribute` accessor over direct access to the columns_hash in the new code.
* Specified column type for quote_valueAlfred Wong2013-07-221-1/+1
| | | | | | | | | | | | | | | | | | | | | When calling quote_value the underlying connection sometimes requires more information about the column to properly return the correct quoted value. I ran into this issue when using optimistic locking in JRuby and the activerecord-jdbcmssql-adapter. In SQLSever 2000, we aren't allowed to insert a integer into a NVARCHAR column type so we need to format it as N'3' if we want to insert into the NVARCHAR type. Unfortuantely, without the column type being passed the connection adapter cannot properly return the correct quote value because it doesn't know to return N'3' or '3'. This patch is fairly straight forward where it just passes in the column type into the quote_value, as it already has the ability to take in the column, so it can properly handle at the connection level. I've added the tests required to make sure that the quote_value method is being passed the column type so that the underlying connection can determine how to quote the value.
* Reset @column_defaults when assigning .kennyj2013-07-141-0/+1
|
* Fix word order in documentation for with_lockPedro Fayolle2013-05-301-1/+1
|
* Deprecate #connection in favour of accessing it via the classBen Moss2013-03-091-2/+2
| | | | | This allows end-users to have a `connection` method on their models without clashing with ActiveRecord internals.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-01-091-1/+1
|\ | | | | | | | | Conflicts: guides/source/getting_started.md
| * remove meaningless use of Relation#allAkira Matsuda2013-01-031-1/+1
| | | | | | | | particularly, `all(options)` would warn
* | Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-1/+1
|/
* 1.9 Syntax related changesAvnerCohen2012-11-101-3/+3
|
* Remove ActiveRecord::ModelJon Leighton2012-10-261-6/+2
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."Jeremy Kemper2012-10-201-1/+1
| | | | This reverts commit 83846838252397b3781eed165ca301e05db39293.
* Get rid of the ActiveRecord::Model::DeprecationProxy thing.Jon Leighton2012-10-191-1/+1
| | | | | | | | | | | | | | | | | I think it's going to be too much pain to try to transition the :active_record load hook from executing against Base to executing against Model. For example, after Model is included in Base, and modules included in Model will no longer get added to the ancestors of Base. So plugins which wish to be compatible with both Model and Base should use the :active_record_model load hook which executes *before* Base gets loaded. In general, ActiveRecord::Model is an advanced feature at the moment and probably most people will continue to inherit from ActiveRecord::Base for the time being.
* The default value can be set once in #column_defaultsJon Leighton2012-08-171-9/+9
| | | | Rather than doing it every time an instance is instantiated.
* Remove instance level quote_value method. This method is private and also ↵kennyj2012-07-141-1/+1
| | | | exists in class method.
* Simplify AR configuration code.Jon Leighton2012-06-151-2/+6
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* Fix #5797. Error calling dup method on AR model with serialized fieldkennyj2012-05-301-1/+1
|
* clear up duplication between Persistence#destroy and Locking#destroyJon Leighton2012-03-301-14/+17
|
* Merge pull request #5334 from courtland/masterJon Leighton2012-03-301-0/+2
|\ | | | | Fix deleting from a HABTM join table upon destroying an object of a model with optimistic locking enabled.
| * Fix deleting from a HABTM join table upon destroying an object of a model ↵Nick Rogers2012-03-071-0/+2
| | | | | | | | with optimistic locking enabled. Issue #5332.
* | Removed flag attributes.Robin Roestenburg2012-03-061-1/+1
|/
* Remove unusused variablesJon Leighton2012-03-041-2/+1
|
* Improve readonly examples and optimistic locking docsCarlos Antonio da Silva2012-01-311-4/+6
| | | | | | | | | * Relation#order can receive order attributes as different arguments, add example; * Readonly does not handle deletion of records, only modification; * locking_version column does not need to default to 0, Rails handles nil values; * Change references from "set_locking_column" to "self.locking_column".
* Add ActiveRecord::Base#with_lockOlek Janiszewski2012-01-181-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add a `with_lock` method to ActiveRecord objects, which starts a transaction, locks the object (pessimistically) and yields to the block. The method takes one (optional) parameter and passes it to `lock!`. Before: class Order < ActiveRecord::Base def cancel! transaction do lock! # ... cancelling logic end end end After: class Order < ActiveRecord::Base def cancel! with_lock do # ... cancelling logic end end end
* Support configuration on ActiveRecord::Model.Jon Leighton2011-12-281-1/+4
| | | | | | | | | | | | | | | The problem: We need to be able to specify configuration in a way that can be inherited to models that include ActiveRecord::Model. So it is no longer sufficient to put 'top level' config on ActiveRecord::Base, but we do want configuration specified on ActiveRecord::Base and descendants to continue to work. So we need something like class_attribute that can be defined on a module but that is inherited when ActiveRecord::Model is included. The solution: added ActiveModel::Configuration module which provides a config_attribute macro. It's a bit specific hence I am not putting this in Active Support or making it a 'public API' at present.
* Deal with global config better between AR::Base and AR::ModelJon Leighton2011-12-241-4/+1
|
* Make read_attribute code path accessible at the class levelJon Leighton2011-12-221-15/+12
|
* remove deprecated set and original methods for table_name, primary_key, etcSergey Nartimov2011-12-211-9/+1
|
* Avoid super; speeds up Model.new by about 12%Jon Leighton2011-12-141-1/+1
|
* Deprecate set_locking_column in favour of self.locking_column=Jon Leighton2011-11-291-8/+13
|
* Added a note that optimistic locking also needs a hidden field to function ↵Joost Baaij2011-10-251-0/+3
| | | | across web workers.
* Consider attempted action in exception message of ActiveRecord::StaleObjectErrorChristian Bäuerlein2011-10-141-2/+2
|
* Includes stale record in StaleObjectErrorChristian Bäuerlein2011-10-141-2/+2
|
* Make it the responsibility of the connection to hold onto an ARel visitor ↵Jon Leighton2011-08-081-2/+2
| | | | for generating SQL. This improves the code architecture generally, and solves some problems with marshalling. Adapter authors please take note: you now need to define an Adapter.visitor_for method, but it degrades gracefully with a deprecation warning for now.