aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
Commit message (Collapse)AuthorAgeFilesLines
* Ensure we are returning either `true` or `false` for `#==`Godfrey Chan2014-03-291-1/+1
| | | | | | 460eb83d cused `ActiveRecord::Base#==` to sometimes return `nil` in some cases, this ensures we always return a boolean value. Also fixed a similar problem in AR reflections.
* Add config to disable schema dump after migrationEmil Soman2014-02-061-0/+9
| | | | | | | | | * Add a config on Active Record named `dump_schema_after_migration` * Schema dump doesn't happen if the config is set to false * Set default value of the config to true * Set config in generated production environment file to false * Update configuration guide * Update CHANGELOG
* Make arel methods private APIRafael Mendonça França2014-02-011-2/+2
| | | | | | Since its conception arel was made to be private API of Active Record. If users want to use arel features directly we should provide a way using the Active Record API without exposing the arel implementation.
* Fixing issue with activerecord serialization not being able to dump a record ↵Mauricio Linhares2014-01-291-1/+1
| | | | after loading it from YAML - fixes #13861
* Move changed_attributes into dirty.rbKeenan Brock2014-01-221-14/+2
| | | Move serialization dirty into serialization.rb
* Restore ActiveRecord states after a rollback for models w/o callbacksGodfrey Chan2014-01-181-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a regression (#13744) that was caused by 67d8bb9. In 67d8bb9, we introduced lazy rollback for records, such that the record's internal states and attributes are not restored immediately after a transaction rollback, but deferred until they are first accessed. This optimization is only performed when the model does not have any transactional callbacks (e.g. `after_commit` and `after_create`). Unfortunately, the models used to test the affected codepaths all comes with some sort of transactional callbacks. Therefore this codepath remains largely untested until now and as a result there are a few issues in the implementation that remains hidden until now. First, the `sync_with_transaction_state` (or more accurately, `update_attributes_from_transaction_state`) would perform the synchronization prematurely before a transaction is finalized (i.e. comitted or rolled back). As a result, when the actuall rollback happens, the record will incorrectly assumes that its internal states match the transaction state, and neglect to perform the restore. Second, `update_attributes_from_transaction_state` calls `committed!` in some cases. This in turns checks for the `destroyed?` state which also requires synchronization with the transaction stae, which causes an infnite recurrsion. This fix works by deferring the synchronization until the transaction has been finalized (addressing the first point), and also unrolled the `committed!` and `rolledback!` logic in-place (addressing the second point). It should be noted that the primary purpose of the `committed!` and `rolledback!` methods are to trigger the relevant transactional callbacks. Since this code path is only entered when there are no transactional callbacks on the model, this shouldn't be necessary. By unrolling the method calls, the intention here (to restore the states when necessary) becomes more clear.
* Ensure Active Record connection consistencyschneems2014-01-091-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently Active Record can be configured via the environment variable `DATABASE_URL` or by manually injecting a hash of values which is what Rails does, reading in `database.yml` and setting Active Record appropriately. Active Record expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot rip out this functionality without deprecating. This presents a problem though when both config is set, and a `DATABASE_URL` is present. Currently the `DATABASE_URL` should "win" and none of the values in `database.yml` are used. This is somewhat unexpected to me if I were to set values such as `pool` in the `production:` group of `database.yml` they are ignored. There are many ways that active record initiates a connection today: - Stand Alone (without rails) - `rake db:<tasks>` - ActiveRecord.establish_connection - With Rails - `rake db:<tasks>` - `rails <server> | <console>` - `rails dbconsole` We should make all of these behave exactly the same way. The best way to do this is to put all of this logic in one place so it is guaranteed to be used. Here is my prosed matrix of how this behavior should work: ``` No database.yml No DATABASE_URL => Error ``` ``` database.yml present No DATABASE_URL => Use database.yml configuration ``` ``` No database.yml DATABASE_URL present => use DATABASE_URL configuration ``` ``` database.yml present DATABASE_URL present => Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url` sub key "wins". If other paramaters `adapter` or `database` are specified in YAML, they are discarded as the `url` sub key "wins". ``` ### Implementation Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge all connection information before returning. This is achieved through a utility class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`. To understand the exact behavior of this class, it is best to review the behavior in activerecord/test/cases/connection_adapters/connection_handler_test.rb though it should match the above proposal.
* Automatically maintain test database schemaJon Leighton2014-01-021-0/+3
| | | | | | | | | | | | | | * Move check from generated helper to test_help.rb, so that all applications can benefit * Rather than just raising when the test schema has pending migrations, try to load in the schema and only raise if there are pending migrations afterwards * Opt out of the check by setting config.active_record.maintain_test_schema = false * Deprecate db:test:* tasks. The test helper is now fully responsible for maintaining the test schema, so we don't need rake tasks for this. This is also a speed improvement since we're no longer reloading the test database on every call to "rake test".
* [ci skip] used new syntax for scopesKuldeep Aggarwal2013-11-271-1/+1
|
* Changed message for Model.inspectArun Agrawal2013-11-091-1/+1
| | | | | | | (No database connection) sounds not be able to connect database. see more #12804
* Merge pull request #12390 from kennyj/rename_to_association_methodsRafael Mendonça França2013-11-051-4/+4
|\ | | | | | | | | | | | | | | | | Renamed generated_feature_methods to generated_association_methods. Conflicts: activerecord/lib/active_record/associations/builder/association.rb activerecord/lib/active_record/associations/builder/singular_association.rb activerecord/test/cases/base_test.rb
| * Renamed generated_feature_methods to generated_association_methods.kennyj2013-09-281-4/+4
| |
* | Revert "ActiveRecord::Base#<=> has been removed. Primary keys may not be in ↵David Heinemeier Hansson2013-11-021-0/+9
|/ | | | | | | | | order," -- will be replaced with a check to ensure that the keys used for comparison are integers, and only fail if they are not. This reverts commit 6256734e2d0bdd89f4b5d11da259d40afa0c95c7. Conflicts: activerecord/CHANGELOG.md
* Merge pull request #10816 from bogdan/less-dirty-dirtyRafael Mendonça França2013-09-231-3/+1
| | | | Make AM::Dirty less dirty to plugin into AR or other library
* Add back options argument in the ActiveRecord::Base.initialize methodRafael Mendonça França2013-09-211-2/+10
| | | | | | | This will make easier to hook protected_attributes gem in our code without making that gem fragile to change in Rails code base. Closes #12243
* support objects with blank string primary keysAaron Patterson2013-09-181-1/+1
|
* ActiveRecord::Base#<=> has been removed. Primary keys may not be in order,Aaron Patterson2013-09-181-9/+0
| | | | | | | | | | | or even be numbers, so sorting by id doesn't make sense. Please use `sort_by` and specify the attribute you wish to sort with. For example, change: Post.all.to_a.sort to: Post.all.to_a.sort_by(&:id)
* do what the superclass does in the case that objects do not matchAaron Patterson2013-09-181-0/+2
|
* Perf: avoid dupes add fallback logic for codersSam2013-09-111-2/+4
|
* Use map! to avoid an extra object creationCarlos Antonio da Silva2013-08-021-1/+1
|
* Remove useless begin..endCarlos Antonio da Silva2013-08-021-2/+1
|
* add a specific factory method rather than using newAaron Patterson2013-07-231-1/+1
|
* Revert "Merge pull request #11299 from ↵Yves Senn2013-07-051-0/+5
| | | | | | | | | | arunagw/disable_implicit_join_references_removed" `disable_implicit_join_references=` was only deprecated on `master`, not with rails 4.0. We can remove it after 4.1 This reverts commit 3c719ead414ffd29e71efce185698af979052abb, reversing changes made to d5c3bf9722abd5733a769c8d789de3f74dbfb92d.
* Remove deprecated `ActiveRecord::Base.disable_implicit_join_references=`.Arun Agrawal2013-07-041-5/+0
|
* push attribute constant cache in to the attribute methods moduleAaron Patterson2013-07-021-6/+0
|
* eagerly initialize the attributes module to avoid check-then-set race conditionsAaron Patterson2013-07-021-7/+1
|
* remove deprecated `ActiveRecord::Base#connection` method.Yves Senn2013-07-011-8/+0
|
* remove deprecated implicit join references.Yves Senn2013-06-291-7/+4
|
* Fix indentationAkira Matsuda2013-06-281-1/+1
|
* `inspect` for AR model classes does not initiate a new connection.Yves Senn2013-06-201-0/+2
|
* fixes a test, and explains why AR::AttributeMethods checks ↵Xavier Noria2013-04-281-1/+3
| | | | defined?(@attributes) in some places
* Fix freeze applying to cloned objectsCaleb Thompson2013-04-151-2/+4
| | | | | | | | | | | | | | | | Previously, freezing a cloned ActiveRecord object froze the original too. By cloning `@attributes` before freezing, we prevent cloned objects (which in Ruby share state of ivars) from being effected by `#freeze`. Resolves issue #4936, which has further information on this issue, as well as steps to reproduce. * Add a test case for `#freeze` not causing `cloned.frozen?` to be true. * Clone @attributes before freezing in `ActiveRecord::Core`, then reassign the cloned, frozen hash to the frozen model's `@attributes` ivar. /cc @steveklabnik
* removes calls to AR::Runtime.instanceXavier Noria2013-04-131-2/+2
| | | | | | | | | | Registries have class-level accessors to write clean code, let's use them. This makes style uniform also with existing usage in ScopeRegistry and InstrumentationRegistry. If performance of the method_missing callback was ever considered to be a concern, then we should stop using it altogether and probably remove the callback. But while we have the feature we should use it.
* Created a runtime registry for thread local variables in active record.wangjohn2013-04-091-2/+2
|
* Bring back ActiveRecord::Base#connection_handler removed by mistake on b37399abRafael Mendonça França2013-04-061-0/+4
|
* Fix typo: overriden => overriDDenAlexander Balashov2013-03-281-2/+2
|
* Make connection_handler overridable per threadSam Saffron2013-03-271-2/+11
|
* Merge pull request #9489 from obrie/fix/overridden_defaults_changed_attributesJeremy Kemper2013-03-241-3/+11
|\ | | | | Fix ActiveRecord locking column defaults not getting persisted
| * Fix ActiveRecord locking column defaults not getting persistedAaron Pfeifer2013-03-181-3/+11
| | | | | | | | | | | | | | | | | | | | | | When partial inserts are enabled, overridden db defaults are ignored. This results in locking columns having a nil value for new records if the db default is null. This happens because the list of changed attributes for new records is always assumed to be empty. Solution: When a new record's default attributes are set, also initialize the list of changed attributes by comparing current values against what's stored as the column defaults in the database.
* | Update other counter caches on destroyIan Young2013-03-201-0/+1
|/
* make it possible to disable implicit join references.Yves Senn2013-03-151-0/+8
| | | | Closes #9712.
* Deprecate #connection in favour of accessing it via the classBen Moss2013-03-091-0/+1
| | | | | This allows end-users to have a `connection` method on their models without clashing with ActiveRecord internals.
* Do not override attributes on `dup` by default scopesHiroshige Umino2013-02-261-1/+0
|
* Reduced memory leak problem in transactions by lazily updating AR objects ↵wangjohn2013-02-201-1/+48
| | | | with new transaction state. If AR object has a callback, the callback will be performed immediately (non-lazily) so the transaction still has to keep records with callbacks.
* Whitespaces :scissors:Rafael Mendonça França2013-01-221-12/+12
| | | | [ci skip]
* Removed reflects_transaction_state.wangjohn2013-01-201-1/+0
|
* Created state for a transaction and added tests.wangjohn2013-01-201-11/+13
|
* Don't allocate new strings in compiled attribute methodsJon Leighton2012-11-211-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves memory and performance without having to use symbols which present DoS problems. Thanks @headius and @tenderlove for the suggestion. This was originally committed in f1765019ce9b6292f2264b4601dad5daaffe3a89, and then reverted in d3494903719682abc0948bef290af0d3d7b5a440 due to it causing problems in a real application. This second attempt should solve that. Benchmark --------- require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') class Post < ActiveRecord::Base connection.create_table :posts, force: true do |t| t.string :name end end post = Post.create name: 'omg' Benchmark.ips do |r| r.report('Post.new') { Post.new name: 'omg' } r.report('post.name') { post.name } r.report('post.name=') { post.name = 'omg' } r.report('Post.find(1).name') { Post.find(1).name } end Before ------ Calculating ------------------------------------- Post.new 1419 i/100ms post.name 7538 i/100ms post.name= 3024 i/100ms Post.find(1).name 243 i/100ms ------------------------------------------------- Post.new 20637.6 (±12.7%) i/s - 102168 in 5.039578s post.name 1167897.7 (±18.2%) i/s - 5186144 in 4.983077s post.name= 64305.6 (±9.6%) i/s - 317520 in 4.998720s Post.find(1).name 2678.8 (±10.8%) i/s - 13365 in 5.051265s After ----- Calculating ------------------------------------- Post.new 1431 i/100ms post.name 7790 i/100ms post.name= 3181 i/100ms Post.find(1).name 245 i/100ms ------------------------------------------------- Post.new 21308.8 (±12.2%) i/s - 105894 in 5.053879s post.name 1534103.8 (±2.1%) i/s - 7634200 in 4.979405s post.name= 67441.0 (±7.5%) i/s - 337186 in 5.037871s Post.find(1).name 2681.9 (±10.6%) i/s - 13475 in 5.084511s
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-11-171-1/+1
|\ | | | | | | | | Conflicts: actionpack/lib/action_dispatch/routing/redirection.rb
| * 1.9 hash syntax changesAvnerCohen2012-11-081-1/+1
| |