aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Merge pull request #6986 from kennyj/fix_6975"Andrew White2013-01-221-14/+5
| | | | | | | | | This reverts commit 8905c1fb496641c3cdb7b3b816ae6d3d4b2c2b73. Closes #8460 Conflicts: activerecord/test/cases/dirty_test.rb
* Revert "Work around undiagnosed bug that's draining a relation's bind_values"Carlos Antonio da Silva2013-01-151-1/+0
| | | | This reverts commit 06cc38a2b0d4778746e8a2a2e2b6aa07e1c1c075.
* Revert "Merge pull request #7983 from georgebrock/bug7950-squashed"Carlos Antonio da Silva2013-01-156-35/+12
| | | | | | | | | | | This reverts commit 88a296dccc401da143d90cad54b693ff06bf2b58, reversing changes made to 666a7e34f553cef4c8878362eafc79c7e3f310c3. Conflicts: activerecord/CHANGELOG.md Reason: this has been resulting in some hard to track bugs and is introducing a possible breackage in a stable version.
* Revert "Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmt"Ernie Miller2013-01-111-14/+0
| | | | | | | This reverts commit ee439895759b38431ad025f3c234831f30dadcdb. It would appear that #7661 had unintended consequences to the API. Until we can sort those out, this should not be in 3.2.x, and wait for 4.0.0.
* Ignore binds payload with nil column in AR log subscriberYasuo Honda2013-01-091-1/+5
| | | | | | | | | | | | | | | | | | | | | | Some tests were raising the following error: Could not log "sql.active_record" event. NoMethodError: undefined method `type' for nil:NilClass` Due to the way binds were being logged, the column info was considered always present, but that is not true for some of the tests listed in the issue. Closes #8806. Conflicts: activerecord/lib/active_record/log_subscriber.rb activerecord/test/cases/log_subscriber_test.rb Conflict resolution: - Revert ruby 1.9 style hash to support ruby 1.8 - Do not include 8f59ffce into 3-2-stable
* Merge branch '3-2-sec' into 3-2-secmergeAaron Patterson2013-01-082-2/+7
|\ | | | | | | | | | | | | | | | | | | | | | | | | * 3-2-sec: bumping version CVE-2013-0156: Safe XML params parsing. Doesn't allow symbols or yaml. * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing with empty hashes. Thanks Damien Mathieu Avoid Rack security warning no secret provided Conflicts: actionpack/CHANGELOG.md activerecord/CHANGELOG.md activesupport/CHANGELOG.md
| * bumping versionAaron Patterson2013-01-081-1/+1
| |
| * * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * ↵Aaron Patterson2013-01-081-1/+6
| | | | | | | | dealing with empty hashes. Thanks Damien Mathieu
* | Refactor write attribute logic to convert number column valueCarlos Antonio da Silva2013-01-071-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an improvement for issue #8673: "Comparing a BigDecimal to true/false on write_attribute is slow" It seems to be an issue with Ruby itself, related to the "coerce" method being called in TrueClass/FalseClass due to the == condition, triggering method_missing, then raising a NameError that's later catched. This issue was also opened in Ruby tracker: https://bugs.ruby-lang.org/issues/7645. This refactoring avoid the coerce call by using a case statement, which gives us better readability as well. A simple benchmark: ---------- require 'benchmark/ips' require 'bigdecimal' Benchmark.ips do |x| x.report("== true") { BigDecimal('3') == true } x.report("TrueClass") { TrueClass === BigDecimal('3') } x.report("== 0") { BigDecimal('3') == 0 } x.report("Numeric") { Numeric === BigDecimal('3') } end Calculating ------------------------------------- == true 6427 i/100ms TrueClass 47297 i/100ms == 0 35923 i/100ms Numeric 55530 i/100ms ------------------------------------------------- == true 75878.5 (±21.6%) i/s - 359912 in 5.004392s TrueClass 1249547.0 (±13.1%) i/s - 6148610 in 5.035964s == 0 666856.3 (±13.3%) i/s - 3268993 in 5.013789s Numeric 1269300.9 (±11.3%) i/s - 6274890 in 5.028458s ---------- Master has a very different implementation, and there are apparently no similar conversions at this point, it's mainly delegated to the column type cast, but I'll check if something needs to be changed there as well. Closes #8673.
* | Fix named scope + class method exampleCarlos Antonio da Silva2013-01-071-3/+1
| | | | | | | | | | | | | | Closes #8804 [ci skip] Conflicts: activerecord/lib/active_record/scoping/named.rb
* | connection_parameters is an Array and will never haveRafael Mendonça França2013-01-061-2/+0
| | | | | | | | prepared_statements as value
* | Fix error when assigning NaN to an integer columnTristan Harward2013-01-061-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also covers any non-castable case by returning nil, which is in-line with the intention of the former implementation, but covers the odd cases which respond to to_i but raise an error when it's called, such as NaN, Infinity and -Infinity. Fixes #8757 Backport of #8781 Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/column_test.rb
* | Fix undefined method `to_i' introduced since 3.2.8Jason Stirk2013-01-041-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes a bug introduced in 96a13fc7 which breaks behaviour of integer fields in 3.2.8. In 3.2.8, setting the value of an integer field to a non-integer (eg. Array, Hash, etc.) would default to 1 (true) : # 3.2.8 p = Post.new p.category_id = [ 1, 2 ] p.category_id # => 1 p.category_id = { 3 => 4 } p.category_id # => 1 In 3.2.9 and above, this will raise a NoMethodError : # 3.2.9 p = Post.new p.category_id = [ 1, 2 ] NoMethodError: undefined method `to_i' for [1, 2]:Array Whilst at first blush this appear to be sensible, it combines in bad ways with scoping. For example, it is common to use scopes to control access to data : @collection = Posts.where(:category_id => [ 1, 2 ]) @new_post = @collection.new In 3.2.8, this would work as expected, creating a new Post object (albeit with @new_post.category_id = 1). However, in 3.2.9 this will cause the NoMethodError to be raised as above. It is difficult to avoid triggering this error without descoping before calling .new, breaking any apps running on 3.2.8 that rely on this behaviour. This patch deviates from 3.2.8 in that it does not retain the somewhat spurious behaviour of setting the attribute to 1. Instead, it explicitly sets these invalid values to nil : p = Post.new p.category_id = [ 1, 2 ] p.category_id # => nil This also fixes the situation where a scope using an array will "pollute" any newly instantiated records. @new_post = @collection.new @new_post.category_id # => nil Finally, 3.2.8 exhibited a behaviour where setting an object to an integer field caused it to be coerced to "1". This has not been retained, as it is spurious and surprising in the same way that setting Arrays and Heshes was : c = Category.find(6) p = Post.new # 3.2.8 p.category_id = c p.category_id # => 1 # This patch p.category_id = c p.category_id # => nil This commit includes explicit test cases that expose the original issue with calling new on a scope that uses an Array. As this is a common situation, an explicit test case is the best way to prevent regressions in the future. It also updates and separates existing tests to be explicit about the situation that is being tested (eg. AR objects vs. other objects vs. non-integers)
* | Merge tag 'v3.2.10' into 3-2-stableMiguel2013-01-031-1/+1
|\| | | | | | | Latest released tag was not fully merged into the stable branch (missed version bumping)
| * bumping version to 3.2.10Aaron Patterson2012-12-231-1/+1
| |
* | Merge branch '3-2-sec' into 3-2-secmergeAaron Patterson2012-12-231-1/+6
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 3-2-sec: CVE-2012-5664 options hashes should only be extracted if there are extra parameters updating changelog updating the changelogs updating the changelog for the CVE Add release date of Rails 3.2.9 to documentation Conflicts: actionmailer/CHANGELOG.md actionpack/CHANGELOG.md activemodel/CHANGELOG.md activerecord/CHANGELOG.md activeresource/CHANGELOG.md activesupport/CHANGELOG.md railties/CHANGELOG.md
| * CVE-2012-5664 options hashes should only be extracted if there are extra ↵Aaron Patterson2012-12-231-1/+6
| | | | | | | | parameters
* | Serialized attribute can be serialized in an integer columnRafael Mendonça França2012-12-211-0/+8
| | | | | | | | | | | | | | | | | | | | Fix #8575 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods/serialization.rb activerecord/test/cases/serialized_attribute_test.rb activerecord/test/models/person.rb
* | Backport #8522, Keep index names when using with sqlite3Yves Senn2012-12-191-1/+1
| | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb activerecord/test/cases/migration/rename_column_test.rb
* | recognize migrations, in folders containing numbers and 'rb'.Yves Senn2012-12-131-1/+1
| | | | | | | | | | | | | | | | | | Backport of #8500 Closes #8492 Conflicts: activerecord/test/cases/migrator_test.rb
* | Allow users to choose the timestamp format in the cache keyRafael Mendonça França2012-12-101-1/+12
| | | | | | | | | | | | This can be done using the class attribute cache_timestamp_format Closes #8195
* | Merge pull request #6376 from jgaskins/timestamp-microsecondsJeremy Kemper2012-12-101-1/+1
| | | | | | | | | | | | Increase numeric-timestamp precision to nanoseconds Conflicts: activesupport/lib/active_support/core_ext/time/conversions.rb
* | Unscope update_column(s) query to ignore default scopeCarlos Antonio da Silva2012-12-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When applying default_scope to a class with a where clause, using update_column(s) could generate a query that would not properly update the record due to the where clause from the default_scope being applied to the update query. class User < ActiveRecord::Base default_scope where(active: true) end user = User.first user.active = false user.save! user.update_column(:active, true) # => false In this situation we want to skip the default_scope clause and just update the record based on the primary key. With this change: user.update_column(:active, true) # => true Backport of #8436 fix. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/persistence.rb activerecord/test/cases/persistence_test.rb
* | Merge pull request #8417 from kennyj/fix_8414Rafael Mendonça França2012-12-041-3/+2
| | | | | | | | | | | | Fix #8414. Performance problem with postgresql adapter primary_key function. Conflicts: activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
* | backport #8403, no intermediate AR objects when eager loading.Yves Senn2012-12-041-2/+4
| | | | | | | | | | | | | | | | | | Closes #3313 Conflicts: activerecord/CHANGELOG.md activerecord/test/models/developer.rb
* | Merge pull request #4942 from bogdan/pluck_joinsJosé Valim2012-12-031-1/+6
| | | | | | | | | | | | | | | | AR::Relation#pluck: improve to work with joins Conflicts: activerecord/lib/active_record/relation/calculations.rb activerecord/test/cases/calculations_test.rb
* | handled respond_to? with private methodsSHIBATA Hiroshi2012-12-031-1/+1
| |
* | Merge pull request #6397 from kennyj/fix_translate_exceptionAaron Patterson2012-11-301-3/+7
| | | | | | | | Fix a problem of translate_exception method in a Japanese (non English) environment.
* | Backport 78b30fed9336336694fb2cb5d2825f95800b541c to fix non-utf-8 databases ↵Jeremy Kemper2012-11-291-5/+19
| | | | | | | | mistakenly getting utf8 collation
* | Merge pull request #7689 from cbarton/assume_migration_version_with_prefix_fixAaron Patterson2012-11-281-1/+1
|\ \ | | | | | | Fixing a schema:load when using a prefix and suffix on the tables [Reopen/backport]
| * | Making test accurately reflect what is going on in the schema migrations testChris Barton2012-09-181-1/+1
| | |
* | | Work around undiagnosed bug that's draining a relation's bind_valuesJeremy Kemper2012-11-281-0/+1
| | |
* | | schema cache already has the columns as a hash, so use thatAaron Patterson2012-11-261-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commits 978ec98c8eff824a60c7e973f369cc7bed1f4d36 and 51676652a3568ad09b06385564de4fdcb13af05e changed database statements to use the schema_cache methods, added on master in c99e34e90d763c52cbe8dc3d950ed1b4db665dc4 and dc973e78560a6514ab172f0ee86dc84a9147d39a But apparently the methods weren't added to schema_cache, resulting in the failure described in #8322 for 3-2-stable. Fixes #8322. Conflicts: activerecord/lib/active_record/connection_adapters/schema_cache.rb
* | | schema cache already has the columns as a hash, so use thatAaron Patterson2012-11-251-1/+1
| | |
* | | speed up fixture loading by querying the schema cache for column namesAaron Patterson2012-11-251-1/+1
| | |
* | | Merge pull request #8311 from alisdair/dirty-nullable-datetimeCarlos Antonio da Silva2012-11-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Don't call will_change! for datetime nil->"". Setting a nil datetime attribute to a blank string should not cause the attribute to be dirty. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
* | | backport #8291, prevent mass assignment of polymorphic type with `build`Yves Senn2012-11-221-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Closes #8265 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/association.rb
* | | Merge pull request #8276 from pwnall/pgsql_text_limitsRafael Mendonça França2012-11-201-0/+7
| | | | | | | | | | | | | | | | | | | | | Postgresql doesn't accepts limits on text columns Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
* | | Be a bit less conservative with mysql in adapterCarlos Antonio da Silva2012-11-191-1/+1
| | | | | | | | | | | | This will allow the new mysql 2.9.0 to be used, fixing our test issues.
* | | Merge pull request #7983 from georgebrock/bug7950-squashedCarlos Antonio da Silva2012-11-166-12/+35
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Backport 4bc2ae0 to fix #7950 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/calculations.rb
| * | | use bind values for join columnsAaron Patterson2012-11-106-12/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a backport of 4bc2ae0da1dd812aee759f6d13ad428354cd0e13. It fixes bug #7950. Conflicts: activerecord/lib/active_record/relation/calculations.rb activerecord/lib/active_record/relation/finder_methods.rb
* | | | Merge pull request #8209 from senny/backport_8176Rafael Mendonça França2012-11-131-1/+3
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | backport #8176, `#pluck` can be used on a relation with `select` clause. Conflicts: activerecord/CHANGELOG.md
| * | | | backport #8176, `#pluck` can be used on a relation with `select` clause.Yves Senn2012-11-131-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/calculations.rb activerecord/test/cases/calculations_test.rb
* | | | | Merge pull request #8204 from nikitug/fix_dynamic_finder_result_checkRafael Mendonça França2012-11-131-1/+1
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use nil? instead of blank? to check dynamic finder result Conflicts: activerecord/CHANGELOG.md
| * | | | | Use nil? instead of blank? to check dynamic finder resultNikita Afanasenko2012-11-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's safe to use `nil?` instead of `blank?` because it's impossible to get an array on finder with bang; `all_by` finder matches against regex without bang: `when /^find_(all_|last_)?by_([_a-zA-Z]\w*)$/`. Fixes #7238
* | | | | | Fix deleting from a HABTM join table upon destroying an object of a model ↵Nick Rogers2012-11-131-0/+2
|/ / / / / | | | | | | | | | | | | | | | with optimistic locking enabled. Fixes #5332.
* / / / / Backport #8074 to 3-2-stable. Use query cache/uncache, when using not only ↵kennyj2012-11-141-6/+6
|/ / / / | | | | | | | | | | | | database.yml but also DATABASE_URL.
* | | | Merge pull request #8154 from bogdan/has_one_association_performanceCarlos Antonio da Silva2012-11-121-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove unwanted transaction when has one association is built Conflicts: activerecord/CHANGELOG.md
* | | | Merge branch '3-2-9' into 3-2-stableSantiago Pastorino2012-11-121-1/+1
|\ \ \ \ | |/ / / |/| | / | | |/ | |/|
| * | Bump to 3.2.9Santiago Pastorino2012-11-121-1/+1
| | |