aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge pull request #23417 from sgringwe/masterRafael Mendonça França2016-03-011-0/+8
|\ | | | | | | Add option to error on ignored order or limit
| * Add initial support for allowing an error on order or limit of queries being ↵Scott Ringwelski2016-02-021-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ignored in batches add some documentation and add 4 tests regarding error vs. warning behavior fix a typo when referring to the message go back to default in tests so that ordering is not important. use a constant instead of method. fix assert_nothing_raised call. use self.klass to allow per class configuration remove logger warn assets as that is tested elsewhere. pass error_on_ignore through find_each and find_in_batches also. add blocks to the finds so that the code is actually executed put the setting back to default in an ensure Add a changelog entry
* | Extract a Relation#arel_attributeMatthew Draper2016-02-041-1/+1
| |
* | Defer Arel attribute lookup to the model classMatthew Draper2016-02-041-0/+5
|/ | | | | This still isn't as separated as I'd like, but it at least moves most of the burden of alias mapping in one place.
* Skip the STI condition when evaluating a default scopeMatthew Draper2016-01-121-1/+1
| | | | | | | | | | | | | Given a default_scope on a parent of the current class, where that parent is not the base class, the parent's STI condition would become attached to the evaluated default scope, and then override the child's own STI condition. Instead, we can treat the STI condition as though it is a default scope, and skip it in this situation: the scope will be merged into the base relation, which already contains the correct STI condition. Fixes #22426.
* Deprecate exception#original_exception in favor of exception#causeYuki Nishijima2015-11-031-2/+2
|
* Merge pull request #20957 from akihiro17/find-by-issueSean Griffin2015-10-201-1/+1
|\ | | | | | | Fix find_by with association subquery issue
| * Don't cache arguments in #find_by if they are an ActiveRecord::Relationakihiro172015-10-061-1/+1
| | | | | | | | | | | | | | In this commit, find_by doesn't cache arguments so that find_by with association subquery works correctly. Fixes #20817
* | applies new doc guidelines to Active Record.Yves Senn2015-10-141-3/+3
|/ | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Separate `dup` from `deep_dup` in the attributes hashSean Griffin2015-09-281-2/+2
| | | | | | | | | | | I'm looking to move towards a tree-like structure for dirty checking that involves an attribute holding onto the attribute that it was created from. This means that `changed?` can be fully encapsulated on that object. Since the objects are immutable, in `changes_applied`, we can simply perform a shallow dup, instead of a deep one. I'm not sure if that will actually end up in a performance boost, but I'd like to semantically separate these concepts regardless
* Extra caller details added to ActiveRecord::RecordNotFoundSameer Rahmani2015-07-211-3/+5
| | | | | | | | | | | | | | | | ActiveRecord::RecordNotFound modified to store model name, primary_key and id of the caller model. It allows the catcher of this exception to make a better decision to what to do with it. For example consider this simple example: class SomeAbstractController < ActionController::Base rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404 private def redirect_to_404(e) return redirect_to(posts_url) if e.model == 'Post' raise end end
* Revert "Revert "Reduce allocations when running AR callbacks.""Guo Xiang Tan2015-07-161-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit bdc1d329d4eea823d07cf010064bd19c07099ff3. Before: Calculating ------------------------------------- 22.000 i/100ms ------------------------------------------------- 229.700 (± 0.4%) i/s - 1.166k Total Allocated Object: 9939 After: Calculating ------------------------------------- 24.000 i/100ms ------------------------------------------------- 246.443 (± 0.8%) i/s - 1.248k Total Allocated Object: 7939 ``` begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' # gem 'rails', github: 'rails/rails', ref: 'bdc1d329d4eea823d07cf010064bd19c07099ff3' gem 'rails', github: 'rails/rails', ref: 'd2876141d08341ec67cf6a11a073d1acfb920de7' gem 'arel', github: 'rails/arel' gem 'sqlite3' gem 'benchmark-ips' end require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection('sqlite3::memory:') ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :users, force: true do |t| t.string :name, :email t.boolean :admin t.timestamps null: false end end class User < ActiveRecord::Base default_scope { where(admin: true) } end admin = true 1000.times do attributes = { name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", email: "foobar@email.com", admin: admin } User.create!(attributes) admin = !admin end GC.disable Benchmark.ips(5, 3) do |x| x.report { User.all.to_a } end key = if RUBY_VERSION < '2.2' :total_allocated_object else :total_allocated_objects end before = GC.stat[key] User.all.to_a after = GC.stat[key] puts "Total Allocated Object: #{after - before}" ```
* copy-edits the docs of dump_schemas [ci skip]Xavier Noria2015-05-061-3/+4
|
* Merge pull request #19448 from tgxworld/fix_activesupport_callbacks_clash_on_runRafael Mendonça França2015-04-061-4/+4
|\ | | | | Fix AS::Callbacks raising an error when `:run` callback is defined.
| * Revert "Reduce allocations when running AR callbacks."Guo Xiang Tan2015-03-221-4/+4
| | | | | | | | This reverts commit 796cab45561fce268aa74e6587cdb9cae3bb243e.
* | Clarify the role of `ActiveRecord::Core.encode_with`Sean Griffin2015-03-291-4/+8
| | | | | | | | Fixes #19568
* | [skip ci] Improve `warn_on_records_fetched` documentationJon Atack2015-03-271-4/+4
| | | | | | | | | | | | | | | | - ‘dection’ -> ‘detection’ - ‘exceeds threshold’ -> ‘exceeds the threshold’ - Other minor improvements.
* | Add `config.active_record.warn_on_records_fetched_greater_than` optionJason Nochlin2015-03-251-0/+9
|/ | | | | | | | | When set to an integer, a warning will be logged whenever a result set larger than the specified size is returned by a query. Fixes #16463 The warning is outputed a module which is prepended in an initializer, so there will be no performance impact if `config.active_record.warn_on_records_fetched_greater_than` is not set.
* Add config.active_record.dump_schemas.Ryan Wallace2015-03-171-0/+9
| | | | | | | Fixes db:structure:dump when using schema_search_path and PostgreSQL extensions. Closes #17157.
* Isolate access to .default_scopes in ActiveRecord::Scoping::DefaultBen Woosley2015-03-121-4/+2
| | | | | | | | | | | Instead use .scope_attributes? consistently in ActiveRecord to check whether there are attributes currently associated with the scope. Move the implementation of .scope_attributes? and .scope_attributes to ActiveRecord::Scoping because they don't particularly have to do specifically with Named scopes and their only dependency, in the case of .scope_attributes?, and only caller, in the case of .scope_attributes is contained in Scoping.
* Attempt to provide backwards compatible YAML deserializationSean Griffin2015-03-101-0/+2
| | | | | | | | | | | | | | | | | | I should have done this in the first place. We are now serializing an explicit version so we can make more careful changes in the future. This will load Active Record objects which were serialized in Rails 4.1. There will be bugs, as YAML serialization was at least partially broken back then. There will also be edge cases that we might not be able to handle, especially if the type of a column has changed. In addition, we're passing this as `from_database`, since that is required for serialized columns at minimum. All other types were serializing the cast value. At a glance, there should be no types for which this is a problem. Finally, dirty checking information will be lost on records serialized in 4.1, so no columns will be marked as changed.
* Revert "mutate the transaction object to reflect state"Aaron Patterson2015-03-021-1/+1
| | | | | | | | This reverts commit 393e65b4170608593ad82377a9eadc918e85698d and ec51c3fedd16b561d096dcc1a6705fdc02ab7666 We don't want the records to hold hard references to transactions because they point at records that have callbacks.
* ask the txn for it's state, not a state objectAaron Patterson2015-03-021-1/+1
| | | | | this way we don't have to mutate a state object, we can just change the state of the txn
* Move transaction code to transaction moduleArthur Neves2015-03-011-41/+0
|
* Remove parent transaction stateArthur Neves2015-03-011-4/+0
| | | | As far as I can tell nobody is setting this variable.
* remove useless conditionalAaron Patterson2015-03-011-1/+1
| | | | | `@reflects_state[depth+1]` will always be nil because we haven't made a method call that would make it true yet.
* Merge pull request #18936 from arthurnn/txn_callbacksArthur Nogueira Neves2015-02-241-1/+1
|\ | | | | Spike on new transaction callbacks
| * Add before_commitArthur Neves2015-02-241-1/+1
| | | | | | | | [fixes #18903]
* | Require `belongs_to` by default.Josef Šimánek2015-02-211-0/+2
| | | | | | | | Deprecate `required` option in favor of `optional` for belongs_to.
* | Merge pull request #16989 from Empact/reload-cache-clearRafael Mendonça França2015-02-201-5/+0
|\ \ | | | | | | | | | Isolate access to @associations_cache and @aggregations_cache to the Associations and Aggregations modules, respectively.
| * | Isolate access to @associations_cache and @aggregations cache to the ↵Ben Woosley2014-09-281-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | Associations and Aggregations modules, respectively. This includes replacing the `association_cache` accessor with a more limited `association_cached?` accessor and making `clear_association_cache` and `clear_aggregation_cache` private.
* | | Merge pull request #16993 from Empact/simplify-find_by-statement-cacheRafael Mendonça França2015-02-201-16/+18
|\ \ \ | |_|/ |/| | | | | Simplify find_by_statement_cache interaction
| * | Simplify `find_by_statement_cache` interaction down to a class-level ivar ↵Ben Woosley2014-09-221-20/+18
| |/ | | | | | | with a single accessor `cached_find_by_statement`.
* | Mark some methods as nodocRafael Mendonça França2015-02-051-6/+6
| | | | | | | | They are implementation details
* | Remove special case for symbols at findRafael Mendonça França2015-02-051-2/+0
| | | | | | | | Deprecated finders are not supported anymore
* | Fix Issue #15549, unbounded memory growth when saving records that have any ↵Will Bryant2015-02-011-2/+3
| | | | | | | | after_create callbacks (or any associations, which makes after_create callbacks for you)
* | make the private methods privateAaron Patterson2015-02-011-2/+2
| |
* | 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.
* | Remove most type related predicates from `Column`Sean Griffin2015-01-301-1/+1
| | | | | | | | | | | | Remaining are `limit`, `precision`, `scale`, and `type` (the symbol version). These will remain on the column, since they mirror the options to the `column` method in the schema definition DSL
* | Merge pull request #18474 from notEthan/pretty_print_inspectSean Griffin2015-01-231-0/+5
|\ \ | | | | | | | | | pretty_print will use #inspect if a subclass redefines it
| * | pretty_print will use #inspect if a subclass redefines itEthan2015-01-121-14/+18
|/ /
* | Remove support for the protected attributes gemCarlos Antonio da Silva2015-01-091-10/+2
| | | | | | | | Related to #10690.
* | Define attribute methods before attempting to populate recordsSean Griffin2015-01-051-1/+1
| | | | | | | | | | | | | | | | `initialize_internals_callback` will attempt to assign attributes from the current scope, which will fail if something defined the method and calls super (meaning it won't hit `method_missing`). Fixes #18339
* | Remove deprecated `ActiveRecord::Base.disable_implicit_join_references=`Rafael Mendonça França2015-01-041-7/+0
| |
* | Pass a type caster when aliasing tables for joinsSean Griffin2014-12-291-4/+4
| |
* | Extract an explicit type caster classSean Griffin2014-12-291-7/+5
| |
* | Rely on the injectable type caster for `arel_table`Sean Griffin2014-12-291-1/+7
| | | | | | | | | | | | | | This API will require much less consuming code to change to accomodate the removal of automatic type casting from Arel. As long as the predicates are constructed using the `arel_table` off of an AR subclass, there will be no changes that need to happen.
* | Remove `klass` and `arel_table` as a dependency of `PredicateBuilder`Sean Griffin2014-12-261-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This class cares far too much about the internals of other parts of Active Record. This is an attempt to break out a meaningful object which represents the needs of the predicate builder. I'm not fully satisfied with the name, but the general concept is an object which represents a table, the associations to/from that table, and the types associated with it. Many of these exist at the `ActiveRecord::Base` class level, not as properties of the table itself, hence the need for another object. Currently it provides these by holding a reference to the class, but that will likely change in the future. This allows the predicate builder to remain wholy concerned with building predicates. /cc @mrgilman
* | Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-1/+5
| | | | | | | | | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* | Don't perform statement caching for `find` when called from a scopeSean Griffin2014-12-221-0/+1
| | | | | | | | | | | | | | | | If there is a method defined such as `find_and_do_stuff(id)`, which then gets called on an association, we will perform statement caching and the parent ID will not change on subsequent calls. Fixes #18117