aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | | | [ci skip] Fix rdoc markupakihiro172015-08-121-1/+1
| | | | | |
* | | | | | docs, tiny rdoc markup fix. [ci skip]Yves Senn2015-08-121-1/+2
|/ / / / / | | | | | | | | | | | | | | | `+` doesn't work around content with spaces fallback `<tt>`.
* | | | | Merge pull request #21205 from akihiro17/fix-docMatthew Draper2015-08-121-13/+13
|\ \ \ \ \ | | | | | | | | | | | | [ci skip] Fix the indentation
| * | | | | [ci skip] Fix the indentationakihiro172015-08-121-13/+13
| | | | | |
* | | | | | Merge pull request #17885 from starbelly/patch-1Yves Senn2015-08-113-14/+31
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add method to run command-line db apps Conflicts: activerecord/CHANGELOG.md
| * | | | | | Add run_cmd class method to ActiveRecord::Tasks::DatabaseTasksstarbelly2015-08-014-17/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added run_cmd() class method to dry up Kernel.system() messages within this namespace and avoid shell expansion by passing a list of arguments instead of a string - Update structure_dump, structure_load, and related tests units to pass a list of params instead of using a string to avoid shell expansion
* | | | | | | Merge pull request #21165 from manlon/masterRafael Mendonça França2015-08-115-3/+34
|\ \ \ \ \ \ \ | |_|/ / / / / |/| | | | | | use correct DB connection for generated HABTM table
| * | | | | | use correct DB connection for generated HABTM tableMatt Hanlon2015-08-075-3/+34
| | | | | | |
* | | | | | | Reference actual classesMiles Starkenburg2015-08-081-5/+5
| | | | | | |
* | | | | | | Remove XML Serialization from core.Zachary Scott2015-08-075-643/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This includes the following classes: - ActiveModel::Serializers::Xml - ActiveRecord::Serialization::XmlSerializer
* | | | | | | Add ActiveRecord::Relation#in_batchesSina Siadat2015-08-076-12/+413
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `in_batches` yields Relation objects if a block is given, otherwise it returns an instance of `BatchEnumerator`. The existing `find_each` and `find_in_batches` methods work with batches of records. The new API allows working with relation batches as well. Examples: Person.in_batches.each_record(&:party_all_night!) Person.in_batches.update_all(awesome: true) Person.in_batches.delete_all Person.in_batches.map do |relation| relation.delete_all sleep 10 # Throttles the delete queries end
* | | | | | Merge pull request #20459Sean Griffin2015-08-063-0/+132
|\ \ \ \ \ \
| * | | | | | Add missing data types for ActiveRecord migrationsMehmet Emin İNAÇ2015-06-083-0/+132
| | | | | | |
* | | | | | | Merge pull request #21092 from vngrs/use_memoization_for_ids_readerRafael Mendonça França2015-08-062-2/+12
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Use memoization for collection associations ids reader
| * | | | | | | Use memoization for collection associations ids readerMehmet Emin İNAÇ2015-08-032-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #21082 remove extra space
* | | | | | | | better docs for ActiveRecord::Migration#table_name_optionsBrendan Buckingham2015-08-061-1/+3
| | | | | | | |
* | | | | | | | Should use `server_info[:version]` instead of `info[:version]`Ryuta Kamizono2015-08-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because `info[:version]` is a client version, the server version is `server_info[:version]`.
* | | | | | | | Fix ambiguous argument warningMehmet Emin İNAÇ2015-08-021-1/+1
|/ / / / / / / | | | | | | | | | | | | | | | | | | | | | encapsulate all arguments
* | | | | | | Fix test failures caused by #20884Sean Griffin2015-08-011-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PostgreSQL is strict about the usage of `DISTINCT` and `ORDER BY`, which one of the tests demonstrated. The order clause is never going to be relevant in the query we're performing, so let's just remove it entirely.
* | | | | | | Merge pull request #20884Sean Griffin2015-08-016-0/+137
|\ \ \ \ \ \ \ | |_|/ / / / / |/| | | | | | | | | | | | | Add #cache_key to ActiveRecord::Relation.
| * | | | | | Add #cache_key to ActiveRecord::Relation.Alberto F. Capel2015-07-206-0/+137
| | | | | | |
* | | | | | | minor AR changelog edits. [ci skip]Yves Senn2015-08-011-9/+8
| | | | | | |
* | | | | | | Decrease string allocations on AR#respond_to?schneems2015-07-291-1/+9
| |_|_|_|_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a symbol is passed in, we call `to_s` on it which allocates a string. The two hardcoded symbols that are used internally are `:to_partial_path` and `:to_model`. This change buys us 71,136 bytes of memory and 1,777 fewer objects per request.
* | | | | | Add `:nodoc:` for internal testing methods [ci skip]Robin Dupret2015-07-281-2/+2
| | | | | |
* | | | | | Merge pull request #20849 from vngrs/misleading_nested_exceptionsRafael Mendonça França2015-07-275-8/+36
|\ \ \ \ \ \ | | | | | | | | | | | | | | Fix misleading errors for has_one through relations
| * | | | | | Fix misleading errors for has_one through relationsMehmet Emin İNAÇ2015-07-225-8/+36
| | | | | | |
* | | | | | | Remove @connection instance variable only when definedYasuo Honda2015-07-261-2/+2
| | | | | | |
* | | | | | | Properly allow uniqueness validations on primary keys.Sean Griffin2015-07-253-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an alternate implementation of #20966. [Sean Griffin & presskey]
* | | | | | | `destroy` shouldn't raise when child associations fail to saveSean Griffin2015-07-244-1/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Deep down in the association internals, we're calling `destroy!` rather than `destroy` when handling things like `dependent` or autosave association callbacks. Unfortunately, due to the structure of the code (e.g. it uses callbacks for everything), it's nearly impossible to pass whether to call `destroy` or `destroy!` down to where we actually need it. As such, we have to do some legwork to handle this. Since the callbacks are what actually raise the exception, we need to rescue it in `ActiveRecord::Callbacks`, rather than `ActiveRecord::Persistence` where it matters. (As an aside, if this code wasn't so callback heavy, it would handling this would likely be as simple as changing `destroy` to call `destroy!` instead of the other way around). Since we don't want to lose the exception when `destroy!` is called (in particular, we don't want the value of the `record` field to change to the parent class), we have to do some additional legwork to hold onto it where we can use it. Again, all of this is ugly and there is definitely a better way to do this. However, barring a much more significant re-architecting for what I consider to be a reletively minor improvement, I'm willing to take this small hit to the flow of this code (begrudgingly).
* | | | | | | Merge pull request #20256 from ↵Sean Griffin2015-07-241-9/+0
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | arunagw/aa-remove-unused-rule-and-task-activerecord Remove unused rule and task from activerecord
| * | | | | | | Remove unused rule and task from activerecordArun Agrawal2015-05-221-9/+0
| | | | | | | |
* | | | | | | | Remove ivar only when definedAkira Matsuda2015-07-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | this fixes a failing test case
* | | | | | | | Improvements on the enum documentation [ci skip]Robin Dupret2015-07-231-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The note regarding the `_prefix` and `_suffix` options is no longer useful since they were renamed specifically for this purpose. Also the given example doesn't show what these options enable and in which case they are really useful (when there are conflicting values for instance). Refs #20999. [Godfrey Chan & Robin Dupret]
* | | | | | | | Rename the enum_{prefix,suffix} options to _{prefix,suffix}Robin Dupret2015-07-233-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes it more clear that they are reserved keywords and also it seems less redundant as the line already starts with the call to the `enum` method.
* | | | | | | | Fixes documentation typo.Дмитро Будник2015-07-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Documentation had extra colon after keyword.
* | | | | | | | fix rails testsMehmet Emin İNAÇ2015-07-211-1/+1
| |/ / / / / / |/| | | | | |
* | | | | | | Extra caller details added to ActiveRecord::RecordNotFoundSameer Rahmani2015-07-215-5/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | | | | | Deprecate and rename the keys for association restrict_dependent_destroyRoque Pinel2015-07-206-4/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously `has_one` and `has_many` associations were using the `one` and `many` keys respectively. Both of these keys have special meaning in I18n (they are considered to be pluralizations) so by renaming them to `has_one` and `has_many` we make the messages more explicit and most importantly they don't clash with linguistical systems that need to validate translation keys (and their pluralizations). The `:'restrict_dependent_destroy.one'` key should be replaced with `:'restrict_dependent_destroy.has_one'`, and `:'restrict_dependent_destroy.many'` with `:'restrict_dependent_destroy.has_many'`. [Roque Pinel & Christopher Dell]
* | | | | | | Ensure that microsecond precision is only used for version of mysql that ↵Jori Hardman2015-07-206-18/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | support it. Fixes #19711
* | | | | | | Fix minor typo in test nameSean Griffin2015-07-201-1/+1
| | | | | | |
* | | | | | | Fix state being carried over from previous transactionRoque Pinel2015-07-203-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This clears the transaction record state when the transaction finishes with a `:committed` status. Considering the following example where `name` is a required attribute. Before we had `new_record?` returning `true` for a persisted record: ```ruby author = Author.create! name: 'foo' author.name = nil author.save # => false author.new_record? # => true ```
* | | | | | | Correctly ignore `mark_for_destruction` without `autosave`Sean Griffin2015-07-204-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As per the docs, `mark_for_destruction` should do nothing if `autosave` is not set to true. We normally persist associations on a record no matter what if the record is a new record, but we were always skipping records which were `marked_for_destruction?`. Fixes #20882
* | | | | | | Merge pull request #20949 from vngrs/missing_method_in_exceptionSean Griffin2015-07-201-1/+1
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Add missing method name to exception description
| * | | | | | | Add missing method name to exception descriptionMehmet Emin İNAÇ2015-07-201-1/+1
| | |/ / / / / | |/| | | | |
* / | | | | | fix doc about ActiveRecord::Transactions::ClassMethods#transaction [ci skip]Mehmet Emin İNAÇ2015-07-201-2/+1
|/ / / / / /
* | | | | | Merge pull request #20946 from schneems/schneems/let-it-goSean Griffin2015-07-196-8/+8
|\ \ \ \ \ \ | | | | | | | | | | | | | | Freeze string literals when not mutated.
| * | | | | | Freeze string literals when not mutated.schneems2015-07-196-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* | | | | | | Fix the test that was broken by #16445 rather than deleting itSean Griffin2015-07-191-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since the counter cache was properly being updated, the model became stale. Simply reloading the model before attempting to destroy is sufficient for this case. I believe this is enough of an edge case to be a valid change to the tests, even though it represents a potential breaking change.
* | | | | | | Fix counter_cache for polymorphic associationsStefan Kanev2015-07-196-16/+34
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also removes a false positive test that depends on the fixed bug: At this time, counter_cache does not work with polymorphic relationships (which is a bug). The test was added to make sure that no StaleObjectError is raised when the car is destroyed. No such error is currently raised because the lock version is not incremented by appending a wheel to the car. Furthermore, `assert_difference` succeeds because `car.wheels.count` does not check the counter cache, but the collection size. The test will fail if it is replaced with `car.wheels_count || 0`.
* | | | | | Merge pull request #20924 from andrii/masterAbdelkader Boudih2015-07-191-1/+1
|\ \ \ \ \ \ | | | | | | | | | | | | | | [ci skip] Fix typo in #any? RDoc