aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
...
| * | If Rails is not defined, check ENV["RAILS_ENV"] and ENV["RACK_ENV"].Keith Gable2014-10-212-1/+90
| |/ | | | | | | | | | | | | This fixes a regression introduced by 6cc03675d30b58e28f585720dad14e947a57ff5b. ActiveRecord, if used without Rails, always checks the "default_env" environment. This would be OK, except that Sinatra also supports environments, and it runs with {RACK|RAILS}_ENV=production. This patch adds a fallback to RAILS_ENV and RACK_ENV (and ultimately default_env) if Rails.env doesn't exist.
* | Use the correct values for int max and minSean Griffin2014-10-313-56/+119
| | | | | | | | | | We had accidentally gone one power of two too far. In addition, we need to handle minimum values as well as the maximum.
* | Treat strings greater than int max value as out of rangeSean Griffin2014-10-319-18/+56
| | | | | | | | | | | | | | | | | | | | | | Sufficiently large integers cause `find` and `find_by` to raise `StatementInvalid` instead of `RecordNotFound` or just returning `nil`. Given that we can't cast to `nil` for `Integer` like we would with junk data for other types, we raise a `RangeError` instead, and rescue in places where it would be highly unexpected to get an exception from casting. Fixes #17380
* | Rename `default_attributes` to `_default_attributes`Sean Griffin2014-10-312-3/+3
| | | | | | | | | | It is internal use only. This is to avoid conflicting with users' method names. Fixes #17458
* | Don't require calculations to be aliased to a columnSean Griffin2014-10-312-2/+1
| | | | | | | | | | | | | | Arel has changed so that `.sum` no longer aliases `SUM(the_column)` to `sum_id`. This means the type returned by the adapter will be at the key `"SUM(the_column)"`. Longer term, we should eventually be able to retain type information from the AR::Base subclasses used in joined queries
* | Prepare for 4.2.0.beta4 releaseGodfrey Chan2014-10-301-1/+1
| |
* | Use released arelGodfrey Chan2014-10-301-1/+1
| |
* | Merge pull request #17440 from claudiob/remove-yet-another-redundant-to-sXavier Noria2014-10-306-11/+11
|\ \ | | | | | | Remove redundant `to_s` in interpolation
| * | Remove redundant `to_s` in interpolationclaudiob2014-10-306-11/+11
| | |
* | | Use `#between`, rather than `#in` for passing Ranges to ArelSean Griffin2014-10-302-2/+2
|/ / | | | | | | Passing ranges to `#in` has been deprecated in Arel.
* | Merge pull request #17434 from claudiob/remove-redundant-to-sXavier Noria2014-10-301-2/+2
|\ \ | | | | | | Remove redundant `to_s` in interpolation
| * | Remove redundant `to_s` in interpolationclaudiob2014-10-291-2/+2
| | |
* | | add bigserial pk supportAaron Patterson2014-10-293-0/+23
|/ /
* | Merge pull request #17411 from ↵Rafael Mendonça França2014-10-291-1/+1
|\ \ | | | | | | | | | | | | mcfiredrill/doc-change-column-default-abstract-mysql-adapter document change_column and change_column_default for abstract_mysql_adapter [ci skip]
| * | :nodoc: for abstract_mysql_adapterTony Miller2014-10-291-1/+1
| | |
* | | fix MySQL enum type lookup with values matching another type. Closes #17402.Yves Senn2014-10-293-6/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The MySQLAdapter type map used the lowest priority for enum types. This was the result of a recent refactoring and lead to some broken lookups for enums with values that match other types. Like `8bit`. This patch restores the priority to what we had before the refactoring. /cc @sgrif
* | | edit pass over all warningsXavier Noria2014-10-287-16/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch uniformizes warning messages. I used the most common style already present in the code base: * Capitalize the first word. * End the message with a full stop. * "Rails 5" instead of "Rails 5.0". * Backticks for method names and inline code. Also, converted a few long strings into the new heredoc convention.
* | | Add mysql and pg specific attributes to Column#== and hashSean Griffin2014-10-282-2/+20
| | |
* | | Merge pull request #17421 from rails/warn-with-heredocXavier Noria2014-10-2813-53/+103
|\ \ \ | | | | | | | | let warn with heredocs
| * | | let's warn with heredocsXavier Noria2014-10-2813-53/+103
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current style for warning messages without newlines uses concatenation of string literals with manual trailing spaces where needed. Heredocs have better readability, and with `squish` we can still produce a single line. This is a similar use case to the one that motivated defining `strip_heredoc`, heredocs are super clean.
* | | 💣Sean Griffin2014-10-282-2/+5
| | | | | | | | | | | | We were relying on hash inequality in tests
* | | Implement hash equality on columnSean Griffin2014-10-281-0/+5
| | | | | | | | | | | | | | | | | | The query cache uses bind values as hash keys. The current implementation relies on reference equality for hash equality. This is brittle, and can easily break in the future.
* | | Implement #== for columnSean Griffin2014-10-281-0/+8
| | | | | | | | | | | | We shouldn't rely on reference equality of these objects in tests
* | | Remove unneccessary default values from relation mergerSean Griffin2014-10-281-2/+2
| | | | | | | | | | | | The value methods will default to an empty array for us automatically
* | | Fix uninitialized ivar warning in testsSean Griffin2014-10-281-1/+1
| | |
* | | Call value methods when merging relations, rather than accessing keysSean Griffin2014-10-281-14/+14
|/ / | | | | | | | | | | | | | | The change to accessing keys directly was originally added to allow `merge` to take a hash. The implementation of `HashMerger` no longer requires us to be doing so. Accessing the values directly makes it impossible to change internal storage details, even if shim methods are added temporarily
* | Allow Relation#rewhere to work with infinite range valuesDan Olson2014-10-272-1/+22
| |
* | Merge pull request #17374 from maurogeorge/scope-exceptionYves Senn2014-10-273-0/+15
|\ \ | | | | | | | | | Raises ArgumentError when try to define a scope without a callable
| * | Raises ArgumentError when try to define a scope without a callableMauro George2014-10-232-0/+9
| |/ | | | | | | | | | | This changes the actual exception `NoMethodError: undefined method `call' for #<ActiveRecord::Relation []>` to a `ArgumentError` when try to define a scope without a callable.
* | Merge pull request #14143 from derekprior/dp-compound-index-orderingYves Senn2014-10-275-5/+9
|\ \ | | | | | | | | | | | | | | | | | | Use type column first in multi-column indexes Conflicts: activerecord/CHANGELOG.md
| * | Use type column first in multi-column indexesDerek Prior2014-10-245-5/+9
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `add_reference` can very helpfully add a multi-column index when you use it to add a polymorphic reference. However, the first column in the index is the `id` column, which is less than ideal. The [PostgreSQL docs][1] say: > A multicolumn B-tree index can be used with query conditions that > involve any subset of the index's columns, but the index is most > efficient when there are constraints on the leading (leftmost) > columns. The [MySQL docs][2] say: > MySQL can use multiple-column indexes for queries that test all the > columns in the index, or queries that test just the first column, the > first two columns, the first three columns, and so on. If you specify > the columns in the right order in the index definition, a single > composite index can speed up several kinds of queries on the same > table. In a polymorphic relationship, the type column is much more likely to be useful as the first column in an index than the id column. That is, I'm more likely to query on type without an id than I am to query on id without a type. [1]: http://www.postgresql.org/docs/9.3/static/indexes-multicolumn.html [2]: http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html
* | Merge pull request #17330 from DanOlson/rewhereMatthew Draper2014-10-273-1/+12
|\ \ | | | | | | Fix Relation#rewhere to work with Range values
| * | Fix Relation.rewhere to work with Range valuesDan Olson2014-10-203-1/+12
| | |
* | | Fix typo in error message when non-boolean value is assigned to boolean columnPrathamesh Sonpatki2014-10-261-1/+1
| | |
* | | Prefix internal method with _Rafael Mendonça França2014-10-255-14/+14
| | | | | | | | | | | | This will avoid naming clash with user defined methods
* | | Fix description of OID in TypeMapInitializerPrathamesh Sonpatki2014-10-251-1/+1
| |/ |/| | | | | [ci skip]
* | Remove duplicate 'select' database statementclaudiob2014-10-205-17/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `select` method has the same definition in almost all database adapters, so it can be moved from the database-specific adapters (PostgreSQl, MySQL, SQLite) to the abstract `database_statement`: ```ruby def select(sql, name = nil, binds = []) exec_query(sql, name, binds) end ``` --- More details about this commit: the only two DB-specific adapters that have a different definition of `select` are MySQLAdapter and MySQL2Adapter. In MySQLAdapter, `select` invokes `exec_query(sql, name, binds)`, so calling `super` achieves the same goal with less repetition. In MySQL2Adapter, `select` invokes `exec_query(sql, name)`, that is, it does not pass the `binds` parameter like other methods do. However, [MySQL2Adapter's `exec_query`](https://github.com/rails/rails/blob/74a527cc63ef56f3d0a42cf638299958dc7cb08c/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb#L228L231) works exactly the same whether this parameters is passed or not, so the output does not change: ```ruby def exec_query(sql, name = 'SQL', binds = []) result = execute(sql, name) ActiveRecord::Result.new(result.fields, result.to_a) end ```
* Merge pull request #17019 from yuki24/add-class-name-to-unknown-attr-errorYves Senn2014-10-203-7/+4
|\ | | | | | | Message on AR::UnknownAttributeError should include the class name of a record
| * AR::UnknownAttributeError should include the class name of a recordYuki Nishijima2014-10-153-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This would be helpful if 2 models have an attribute that has a similar name to the other. e.g: before: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute: name after: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
* | AR::UnknownAttributeError should include the class name of a recordYuki Nishijima2014-10-203-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This would be helpful if 2 models have an attribute that has a similar name to the other. e.g: before: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute: name after: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
* | [ci skip] Make merge method nodocAnshul Sharma2014-10-201-8/+1
| |
* | [ci skip] merge docsAnshul Sharma2014-10-201-0/+7
| |
* | Fixed test throwing unused variable warningVipul A M2014-10-191-1/+1
| |
* | Merge pull request #17302 from ↵Rafael Mendonça França2014-10-181-3/+3
| | | | | | | | | | | | claudiob/replace-slower-block-call-with-faster-yield Replace (slower) block.call with (faster) yield
* | Revert "Replace (slower) block.call with (faster) yield"Zachary Scott2014-10-181-3/+3
| | | | | | | | This reverts commit 0ab075e75f58bf403f7ebe20546c7005f35db1f6.
* | Replace (slower) block.call with (faster) yieldclaudiob2014-10-181-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Performance optimization: `yield` with an implicit `block` is faster than `block.call`. See http://youtu.be/fGFM_UrSp70?t=10m35s and the following benchmark: ```ruby require 'benchmark/ips' def fast yield end def slow(&block) block.call end Benchmark.ips do |x| x.report('fast') { fast{} } x.report('slow') { slow{} } end # => fast 154095 i/100ms # => slow 71454 i/100ms # => # => fast 7511067.8 (±5.0%) i/s - 37445085 in 4.999660s # => slow 1227576.9 (±6.8%) i/s - 6145044 in 5.028356s ```
* | Add a deprecation warning for abiguous boolean valuesSean Griffin2014-10-162-5/+14
| | | | | | | | | | | | | | | | | | | | | | In Rails 5.0, we'd like to change the behavior of boolean columns in Rails to be closer to Ruby's semantics. Currently we have a small set of values which are "truthy", and all others are "falsy". In Rails 5.0, we will reverse this to have a small number of values which are "falsy", and all others will become "truthy". In the interim, all values which are ambiguous must emit a deprecation warning.
* | test, better describe `SerializationTypeMismatch` behavior. refs #14716.Yves Senn2014-10-162-4/+3
| |
* | pg, test assigning non-array values to an array column. Closes #14716.Yves Senn2014-10-161-0/+9
| | | | | | | | | | | | The behavior has changed since 4.1 and non-array values are no longer type casted to a blank array. This way the user can define custom validations on that property.
* | docs, since #16702 we detect mutation on serialized attributes. [ci skip]Yves Senn2014-10-161-3/+0
| | | | | | | | /cc @sgrif