aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* No need to call to_sym hereGodfrey Chan2014-09-202-9/+9
| | | | | The hash is now string-keyed, and [_]reflect_on_association calls `to_s` on the argument anyway.
* Merge pull request #15791 from zev/add_model_to_recordnotfound_messageAaron Patterson2014-09-191-8/+8
|\ | | | | Update RecordNotFound exception cases to include a message with the
| * Update RecordNotFound exception cases to include a message with theZev Blut2014-06-181-8/+8
| | | | | | | | Model that the Record was not found in.
* | A `NullRelation` should represent nothing. Closes #15176.Yves Senn2014-09-111-2/+2
| | | | | | | | | | | | [Matthew Draper & Yves Senn] Closes #16860. (pull request to discuss the implementation)
* | Fix query with nested array in Active RecordCristian Bica2014-09-061-4/+12
| | | | | | | | | | | | | | | | `User.where(id: [[1,2],3])` was equal to `User.where(id:[1, 2, 3])` in Rails 4.1.x but because of some refactoring in Arel this stopped working in 4.2.0. This fixes it in Rails. [Dan Olson & Cristian Bica]
* | Fixed regression with referencing polymorphic assoc in eager-loadGodfrey Chan2014-09-051-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | This is cased by 03118bc + 9b5d603. The first commit referenced the undefined local variable `column` when it should be using `reflection.type` as the lookup key. The second commit changed `build_arel` to not modify the `bind_values` in- place so we need to combine the arel's `bind_values` with the relation's when building the SQL. Fixes #16591 Related #15821 / #15892 / 7aeca50
* | always reorder bind parameters. fixes #15920Aaron Patterson2014-09-041-6/+4
| |
* | Avoid using heredoc for user warningsGodfrey Chan2014-08-281-4/+2
| | | | | | | | | | | | | | | | | | | | Using heredoc would enforce line wrapping to whatever column width we decided to use in the code, making it difficult for the users to read on some consoles. This does make the source code read slightly worse and a bit more error-prone, but this seems like a fair price to pay since the primary purpose for these messages are for the users to read and the code will not stick around for too long.
* | Fixes the `Relation#exists?` to work with polymorphic associations.Kassio Borges2014-08-181-1/+1
| | | | | | | | Fixes #15821.
* | Check attributes passed to create_with and whereRafael Mendonça França2014-08-181-2/+14
| | | | | | | | | | | | | | | | | | | | | | If the request parameters are passed to create_with and where they can be used to do mass assignment when used in combination with Relation#create. Fixes CVE-2014-3514 Conflicts: activerecord/lib/active_record/relation/query_methods.rb
* | Fixed AR::Relation#where edge case with Hash and other RelationBogdan Gusiev2014-08-141-3/+15
| | | | | | | | | | | | Example: Author.where(posts: { author_id: Author.where(country_id: 1) }).joins(:posts)
* | remove blank lines in the start of the ActiveRecord filesPonomarev Nikolay2014-07-291-1/+0
| |
* | Fix typo in commentCade Truitt2014-07-021-1/+1
| |
* | Encapsulate knowledge of type objects on `ActiveRecord::Result`Sean Griffin2014-06-221-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Attempting to reduce the number of places that care about the details of how type casting occurs. We remove the type casting of the primary key in `JoinDependecy`, rather than encapsulating it. It was originally added for consistency with https://github.com/rails/rails/commit/40898c8c19fa04442fc5f8fb5daf3a8bdb9a1e03#diff-06059df8d3dee3101718fb2c01151ad0R211, but that conditional was later removed in https://github.com/rails/rails/commit/d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734. What is important is that the same row twice will have the same value for the primary key, which it will.
* | Don't use `Column` for type casting in Relation calculationsSean Griffin2014-06-181-12/+8
| |
* | [ci skip] add API doc for AR Group.Aditya Kapoor2014-06-171-1/+9
| |
* | Pluck should work with columns of the same name from different tablesSean Griffin2014-06-111-3/+1
|/ | | | | | | | The column name given by the adapter doesn't include the table namespace, so going through the hashed version of the result set causes overridden keys. Fixes #15649
* ActiveRecord::FinderMethods.find passes proc parameter #15382James Yang2014-06-101-1/+1
|
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-2/+2
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* reuse available belongs_to? methodeileencodes2014-06-031-1/+1
| | | | | | | | | | Reflection has a `belongs_to?` method. Instead of checking for `macro == :belongs_to` throughout the source reuse existing method. I also bumped `foreign_key_present?` method onto on line because the `belongs_to?` makes it shorter than other longer lines in the same class.
* Remove unused `initialize_attributes` methodSean Griffin2014-06-021-1/+1
| | | | | This was previously a hook for a special case related to `serialize`, which has since been removed.
* Merge pull request #14834 from al2o3cr/issue14155Aaron Patterson2014-05-271-1/+10
|\ | | | | Correctly alias table names when joining more than once
| * WIP: pass existing joins to construct_join_dependencyMatt Jones2014-05-161-1/+10
| |
* | Allow empty arrays in where predicatesSean Griffin2014-05-261-0/+2
| |
* | Merge pull request #15300 from arthurnn/refactor_reflectionsRafael Mendonça França2014-05-262-3/+3
|\ \ | | | | | | Refactor reflections
| * | Merge pull request #15210 from arthurnn/fix_hbtm_reflectionArthur Neves2014-05-242-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Fix habtm reflection Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/counter_cache.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/reflection_test.rb
* | | Refactor the handling of arrays in where predicatesSean Griffin2014-05-261-11/+14
|/ / | | | | | | | | | | Simplifies the code slightly, isolates non-nil non-range values into a single array, which will make it easier to do things like apply type casting to them in the future.
* | Remove duplicated parameter check on #where!Sergey Alekseev2014-05-231-8/+4
| | | | | | | | | | | | | | | | | | | | It seems that #where! is not designed to be used as a chained where. See initial implementation at 8c2c60511beaad05a218e73c4918ab89fb1804f0. So, no need to check twice. We should not test #where! https://github.com/rails/rails/pull/15285#discussion_r13018316
* | Removed not-used codePaul Nikitochkin2014-05-221-1/+0
|/
* Merge pull request #15078 from nbudin/fix_merger_filter_binds_comparison_masterRafael Mendonça França2014-05-141-1/+1
|\ | | | | | | | | | | | | Make filter_binds filter out symbols that are equal to strings Conflicts: activerecord/CHANGELOG.md
| * Make filter_binds filter out symbols that are equal to stringsNat Budin2014-05-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | ActiveRecord::Relation::Merger's filter_binds method does not filter out bind variables when one of the attribute nodes has a string name, but the other has a symbol name, even when those names are actually equal. This can result in there being more bind variables than placeholders in the generated SQL. This is particularly an issue for PostgreSQL, where this is treated as an error. This patch changes the filter_binds method to make it convert both attribute names to strings before comparing.
* | docs, explain usage of `count` + `select`. Closes #15065. [ci skip]Yves Senn2014-05-131-0/+8
|/
* Put back Relation#join method as a delegate to ArrayBogdan Gusiev2014-05-051-1/+1
| | | | | | | | This is a regression 4.0 -> 4.1 fix. In 4.1.0 Relation#join is delegated to Arel#SelectManager. In 4.0 series it is delegated to Array#join This patch puts back the behaviour of 4.0
* push up bind params on "simple" subquery calculationsAaron Patterson2014-05-021-2/+4
| | | | | bind parameters we not being propogated to simple subquery calculation calls. This fixes it
* Give real privacy to class methods in AR::PredicateBuilderHector Satre2014-05-011-7/+8
|
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-254-5/+25
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (28 commits) move AR length validation tests into separate test-case. No need for trailing slash on migration path. reset `@arel` when modifying a Relation in place. PostgreSQL Timestamps always map to `:datetime`. [ci skip] Improve formatting and yml Fix a typo in the doc of forty_two AR FinderMethod Improve readability of contributing to rails guide. [ci skip] Precompile the image we're referencing, too. `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions. Fixed an issue with migrating legacy json cookies. Correct comment [ci skip] Perfer to define methods instead of calling test Fix syntax error Add CHANGELOG entry for #14757 [ci skip] Fix run-on sentences and improve grammar [skip ci] Add test for using ActionView::Helpers::FormHelper.label with block and html select! renamed to avoid name collision Array#select! Rearrange deck chairs on the titanic. Organize connection handling test cases. Change favicon_link_tag helper mimetype from image/vnd.microsoft.icon to image/x-icon. ActionController::Renderers documentation fix ...
| * reset `@arel` when modifying a Relation in place.Yves Senn2014-04-241-0/+12
| | | | | | | | /cc @tenderlove
| * Fix a typo in the doc of forty_two AR FinderMethodEric Bouchut2014-04-241-1/+1
| |
| * Merge pull request #14757 from estsauver/14752Rafael Mendonça França2014-04-223-4/+12
| |\ | | | | | | Fix behavior of select! to be consistent with select #14752
| | * select! renamed to avoid name collision Array#select!Earl J St Sauver2014-04-213-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | Fixes #14752 Select mimics the block interface of arrays, but does not mock the block interface for select!. This change moves the api to be a private method, _select!.
* | | Merge branch 'master' into adequaterecordAaron Patterson2014-04-201-1/+1
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (74 commits) [ci skip] builtin -> built-in Fix code indentation and improve formatting Grammar fix in Getting Started Guide Make URL escaping more consistent Optimize URI escaping Always escape string passed to url helper. Remove statement assuming coffee shop/public space wifi is inherently insecure Don't rely on Arel master in bug report template [ci skip] wrap methods in backticks [ci skip] "subhash" --> "sub-hash" multibyte_conformance.rb --> multibyte_conformance_test.rb Fix inconsistent behavior from String#first/#last `@destroyed` should always be set to `false` when an object is duped. remove warning `warning: ambiguous first argument; put parentheses or even spaces` :uglify -> :uglifier Regression test for irregular inflection on has_many Singularize association names before camelization Fix spelling and proper nouns Optimize select_value, select_values, select_rows and dry up checking whether to exec with cache for Postgresql adapter Include default rails protect_from_forgery with: :exception ... Conflicts: activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
| * | Make sure the column_name is different from 'all'.Lauro Caetano2014-04-141-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 968c581ea34b5236af14805e6a77913b1cb36238 have fixed the EagerLoadTest, but not in the correct way. The problem was when `empty?` or `size` was called on relation. It was triggering `count(:all)`, which was passing `:all` as the column name to `count` on Calculations. On the other hand, the method `calculate` on Calculations was calling `construct_relation_for_association_calculations` instead of `perform_calculation`, because `has_include?` was returning `true` since `column_name` was present. To prevent calling the wrong method to perform the calculation, we have to check if the `column_name` is present and if it is different from `:all` (which is now used to correctly do `count` with `select`). More information here: https://github.com/rails/rails/commit/968c581ea34b5236af14805e6a77913b1cb36238#commitcomment-6006135
* | Merge branch 'master' into adequaterecordAaron Patterson2014-04-141-14/+22
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (70 commits) [ci skip] Added link to ruby-lang.org installation. Use the index on hidden field `collection_check_boxes` respects `:index` option for the hidden filed name. docs, double meaning of `serialize` argument. Closes #14284. Just call read_attribute, no need to use `send`. - Fix lingering reference to `:text` instead of the newer `:plain` - Section references `form_tag` instead of the `form_for` used in the example again, read_attribute is public, so just call it read_attribute is public, so we should just call it Disable assest cache store in docs [ci skip] Make counter cache decrementation on destroy idempotent Write the failing test case for concurrent counter cache [ci skip] Use plain underscore instead of "\_". Update documentation to use Rails.application instead Add a changelog entry for #14546 [ci skip] Move tests for deep_dup and duplicable to object directory Missing 'are' in note - [ci skip] CollectionHelpers now accepts a readonly option Fix a few typos [ci skip] Bundle tzinfo-data on :x64_mingw (64-bit Ruby on Windows). don't bother with an offset if the offset is zero ...
| * don't bother with an offset if the offset is zeroAaron Patterson2014-04-121-6/+9
| | | | | | | | | | we're guaranteed to pass a numeric value for offset, so if it's zero, just don't add an offset to the query
| * only add the offset and index when we need toAaron Patterson2014-04-121-8/+9
| |
| * remove branching logic from calls to find_nthAaron Patterson2014-04-121-6/+10
| |
* | Merge branch 'master' into adequaterecordAaron Patterson2014-04-073-6/+9
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (122 commits) Rails.application should be set inside before_configuration hook remove check for present? from delete_all Remove useless begin..end Build the reverse_order on its proper method. Use connection-specific bytea escaping Ignore order when doing count. make enums distinct per class Remove unused `subclass_controller_with_flash_type_bar` var from flash test. fix CollectionProxy delete_all documentation Added OS X specific commands to installation guide [ci skip] Recommended using homebrew for installing MySQL and PostgreSQL Fix setup of adding _flash_types test. Use SVG version of travis build status badge [skip ci] W3C CSP document moved to gihub.io URL [ci skip] sprockets-rails was released Fix the test defining the models in the right place Add CHANGELOG entry for #11650 [ci skip] Declare the assets dependency Use sass-rails 4.0.3 Make possible to use sprockets-rails 2.1 add missing parentheses to validates_with documentation [skip ci] ...
| * Build the reverse_order on its proper method.Lauro Caetano2014-04-072-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The reverse_order method was using a flag to control if the order should be reversed or not. Instead of using this variable just build the reverse order inside its proper method. This implementation was leading to an unexpected behavior when using reverse_order and then applying reorder(nil). Example: Before Post.order(:name).reverse_order.reorder(nil) # => SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC After Post.order(:name).reverse_order.reorder(nil) # => SELECT "posts".* FROM "posts"
| * Ignore order when doing count.Lauro Caetano2014-04-071-1/+1
| | | | | | | | | | | | | | This is necessary because Postgresql doesn't play nice with ORDER BY and no GROUP BY. Fixes #14621.
| * Merge branch 'master' of github.com:rails/docrailsVijay Dev2014-03-291-1/+5
| |\