aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-251-2/+14
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
| * select! renamed to avoid name collision Array#select!Earl J St Sauver2014-04-211-2/+2
| | | | | | | | | | | | | | | | 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-071-4/+8
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-071-3/+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"
| * Merge branch 'master' of github.com:rails/docrailsVijay Dev2014-03-291-1/+5
| |\
| | * Update documentation on group method to indicate it takes an arrayEarl St Sauver2014-03-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | The group method also takes an array, however this isn't immediately clear by reading the source since it delegates this method. If you trace it back to the AREL building you can see that it does support an array. Shoutout to @betovelandia for pointing this out.
| | * Fix misspelling in references docsSteven Harman2014-03-141-1/+1
| | |
* | | Merge branch 'master' into adequaterecordAaron Patterson2014-03-251-0/+2
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (96 commits) clarify CHANGELOG [ci skip]. Fix Generation of proper migration when ActiveRecord::Base.pluralize_table_names = false. update comments to reflect that options support is not available synchronize changelogs and 4.1 release notes. [ci skip] do not rely on method_missing hitting arel use ARel factory methods for building AST nodes Fix date_select option overwriting html classes - Rename `increment_or_decrement` to an apt `set_cache_value` since it actually doesn't increment/decrement in localstore. Check if any sqlite files are not included in the gitignore Remove sqlite3 lines from .gitignore if the application is not using sqlite3. Adding active_model in Rails::Info Clean up tables after each test. Swapped parameters of assert_equal in assert_select Update test helper to use latest Digestor API Digestor should just rely on the finder to know about the format and the variant -- trying to pass it back in makes a mess of things (oh, and doesnt work) Log the full path, including variant, that the digestor is trying to find Fix for digestor to consider variants for partials -- this still needs more testing!! fix log_tags request object grammar Extract with_example_table into helper method. test for structure:dump without schema information table. refs eafec46 ... Conflicts: activerecord/test/cases/relation/where_chain_test.rb
| * | `where.not` adds `references` for `includes`.Yves Senn2014-03-171-0/+2
| |/ | | | | | | Closes #14406.
* | Merge branch 'master' into adequaterecordAaron Patterson2014-03-131-17/+22
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (108 commits) make tests pass on Ruby 2.2 Use Sqlite3 adapter in examples use the body proxy to freeze headers just ask the response for the commit status, we do not need to ask the jar only write the jar if the response isn't committed Fix a grammatical error in the i18n guide [ci skip] use method_defined? to check whether or not a method is defined Enhance docs for update_attribute [ci-skip] Change usec to 0 on tests that compare seconds Unit test for mysql quote time usec Changelog entry for mysql56 microseconds Test microsecond on mysql 5.6 MySQL 5.6 and later supports microsecond precision in datetime. [ci skip] Add documentation for original_fullpath. Remove mocking on save, when not necessary comment why we are modifying global state. [ci skip] `change_table` supports `citext`. Follow up to #12523. Removed unnecessary command "application" register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester] Fixes STI when 2+ levels deep. ...
| * get rid of intermediate arrays.Yves Senn2014-03-051-2/+3
| | | | | | | | origin: https://github.com/rails/rails/commit/f6aeb8b1a3687c8523e4a56309fe3736011b2935#commitcomment-5569649
| * we only need to support `asc` and `ASC`. No need for mixed cases. #14263Yves Senn2014-03-051-13/+14
| | | | | | | | This is a result of the discussion at https://github.com/rails/rails/pull/14263/files#r10291489
| * Allow string hash values on AR order methodMarcelo Casiraghi2014-03-041-3/+6
| | | | | | | | | | | | | | | | | | This behavior has almost no performance impact: String not allowed 66.910000 0.030000 66.940000 ( 67.024976) String allowed 69.360000 0.030000 69.390000 ( 69.503096) Benchmarked with http://git.io/Y0YuRw.
| * [ci skip] correct select examples and doc, ref [522c0fd]Kuldeep Aggarwal2014-03-011-4/+4
| |
* | Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-5/+3
|\| | | | | | | | | | | | | | | | | | | * master: Revert "Merge pull request #13344 from ccutrer/fix-from-default-select" No need to use symbols Don't skip tests if they are not broken. Just don't define they Fix typo [ci skip] Resolve encoding issues with arrays of hstore (bug 11135). Fix coffeescript sample [ci skip]
| * Revert "Merge pull request #13344 from ccutrer/fix-from-default-select"Rafael Mendonça França2014-02-171-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 3ea840355409dc205a9e0d027fc09f1452636969, reversing changes made to e4cde5d58cbb09d1843796f96ba86225ff94fe05. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/query_methods.rb Reason: using `from` without `select` should not change the select list to SELECT * because it can lead different query results. If it is needed to change the table to a subquery or a view you can pass a table alias in the `from` call or use `select('subquery.*')`. Fixes #14049.
| * No need to use symbolsRafael Mendonça França2014-02-161-3/+3
| |
* | Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-17/+26
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (311 commits) Add a missing changelog entry for #13981 and #14035 Revert "Fixed plugin_generator test" implements new option :month_format_string for date select helpers [Closes #13618] add factory methods for empty alias trackers guarantee a list in the alias tracker so we can remove a conditional stop exposing table_joins make most parameters to the AliasTracker required make a singleton for AssociationScope pass the association and connection to the scope method pass the tracker down the stack and construct it in the scope method clean up add_constraints signature remove the reflection delegate remove klass delegator remove railties changes. fixes #14054 remove chain delegate remove scope_chain delegate Add verb to sanitization note fix path shown in mailer's templates updated Travis build status image url fix guide active_support_core_extensions. add Note to String#indent [ci skip] ... Conflicts: activerecord/lib/active_record/associations/join_dependency.rb activerecord/test/cases/associations/association_scope_test.rb
| * Make arel methods private APIRafael Mendonça França2014-02-011-4/+3
| | | | | | | | | | | | Since its conception arel was made to be private API of Active Record. If users want to use arel features directly we should provide a way using the Active Record API without exposing the arel implementation.
| * Let `unscope` ignore non Arel scope.where_valuesWashington Luiz2014-01-301-2/+0
| |
| * docs, `references` is only used with `includes`. Closes #13727.Yves Senn2014-01-301-9/+14
| | | | | | | | | | | | | | There is no gain in `referencing` tables that are not used for preloading. Furthermore it will break if polymorphic associations are invloved. This is because `references_eager_loaded_tables?` uses all `reference_values` to decide wether to `eager_load` or `preload`.
| * Handle aliased attributes in AR::Relation#select, #order, etc.Tsutomu Kuroda2014-01-291-1/+5
| | | | | | | | | | | | | | With this we can write `Model#select(:aliased)`, `Model#order(:aliased)`, `Model#reoder(aliased: :desc)`, etc. Supplementary work to 54122067acaad39b277a5363c6d11d6804c7bf6b.
| * Display value when raising due to unscope() issuesWashington Luiz2014-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Hopefully make it easier to debug errors. e.g Before: RuntimeError: unscope(where: "deleted_at") failed: unscoping String is unimplemented. After: RuntimeError: unscope(where: "deleted_at") failed: unscoping String "'t'='t'" is unimplemented.
| * prepend table name for `Relation#select` columns.Yves Senn2014-01-211-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a bug where `select(:id)` combined with `joins()` raised: ``` ActiveRecord::StatementInvalid: SQLite3::SQLException: ambiguous column name: id: SELECT id, authors.author_address_id FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY posts.id LIMIT 3 ``` The `select_values` are still String and Symbols because other parts (mainly calculations.rb) rely on that fact. /cc @tenderlove
* | Remove outdated comment.Rafael Mendonça França2014-01-171-1/+0
| | | | | | | | | | | | | | The code duplication was removed and this comment is pointing to the wrong line. [ci skip]
* | use a params hash so we know what bind parameters are usedAaron Patterson2014-01-151-1/+1
| |
* | reorder bind indexes if joins produced bind valuesAaron Patterson2014-01-141-0/+9
| |
* | take in to account existing bind parameters when building the bind listAaron Patterson2014-01-141-21/+20
| |
* | unscoping a where should remove bind valuesAaron Patterson2014-01-141-0/+2
| |
* | remove dead codeAaron Patterson2014-01-141-2/+0
| |
* | we should not be copying these. fixes ↵Aaron Patterson2014-01-141-4/+0
| | | | | | | | test_find_all_using_where_with_relation_with_bound_values
* | fixing column alias resolutionAaron Patterson2014-01-131-1/+1
| |
* | do not clear out bind parameters on unscopeAaron Patterson2014-01-131-3/+0
| |
* | Merge branch 'master' into set_bindsAaron Patterson2014-01-131-4/+6
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (24 commits) unscope should remove bind values associated with the where reverse_order_value= is not private, so no need to send avoid more dynamic symbols no need to to_sym recover from test runs that leave the database in a bad state updates screenshot data [ci skip] "serie" => "series" revises a few things in the getting started guide [ci skip] Favor canonical environment variables for secrets removed extra comma [ci skip] Only lookup `config.log_level` for stdlib `::Logger`. Closes #11665. Updated Changelog to reflect removal of :dependent => :restrict standardize on jruby_skip & rbx_skip fix bug in becomes! when changing from base to subclass. Closes #13272. highlight http://localhost:3000 in README.md. Closes #13643. [ci skip] doc proc/lambda arg on inclusion validation. Closes #13689. [ci skip] Skip Spring App Generator tests on JRuby fixes a typo in a CHANGELOG upgrade SDoc fixes the Gemfile generator templates ... Conflicts: activerecord/test/cases/hot_compatibility_test.rb
| * unscope should remove bind values associated with the whereAaron Patterson2014-01-131-0/+2
| |
| * reverse_order_value= is not private, so no need to sendAaron Patterson2014-01-131-1/+1
| | | | | | | | It's not public API, but is not private scoped.
| * avoid more dynamic symbolsAaron Patterson2014-01-131-1/+1
| |
| * no need to to_symAaron Patterson2014-01-131-2/+2
| |
* | adding bind values to the manager objectAaron Patterson2014-01-131-1/+1
| |
* | bubble bind parameters up when building join dependenciesAaron Patterson2014-01-131-2/+5
| |
* | Merge branch 'master' into set_bindsAaron Patterson2014-01-111-94/+127
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (2794 commits) doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip] Restore DATABASE_URL even if it's nil in connection_handler test [ci skip] - error_messages_for has been deprecated since 2.3.8 - lets reduce any confusion for users Ensure Active Record connection consistency Revert "ask the fixture set for the sql statements" Check `respond_to` before delegation due to: https://github.com/ruby/ruby/commit/d781caaf313b8649948c107bba277e5ad7307314 Adding Hash#compact and Hash#compact! methods MySQL version 4.1 was EOL on December 31, 2009 We should at least recommend modern versions of MySQL to users. clear cache on body close so that cache remains during rendering add a more restricted codepath for templates fixes #13390 refactor generator tests to use block form of Tempfile Fix typo [ci skip] Move finish_template as the last public method in the generator Minor typos fix [ci skip] make `change_column_null` reversible. Closes #13576. create/drop test and development databases only if RAILS_ENV is nil Revert "Speedup String#to" typo fix in test name. [ci skip]. `core_ext/string/access.rb` test what we are documenting. Fix typo in image_tag documentation ... Conflicts: activerecord/lib/active_record/associations/join_dependency/join_association.rb activerecord/lib/active_record/relation/query_methods.rb
| * raise `ArgumentError` exception if `Model.where.not` is called with `nil` ↵Kuldeep Aggarwal2013-12-301-0/+2
| | | | | | | | argument
| * fix default select when from is usedCody Cutrer2013-12-191-1/+3
| |
| * #none documentation updated [ci skip]Akshay Vishnoi2013-12-181-5/+4
| |
| * Spelling and Grammar check [ci skip]Akshay Vishnoi2013-12-161-2/+2
| |
| * Merge remote-tracking branch 'docrails/master'Xavier Noria2013-11-241-4/+4
| |\ | | | | | | | | | | | | | | | Conflicts: activesupport/lib/active_support/core_ext/hash/deep_merge.rb activesupport/lib/active_support/core_ext/hash/keys.rb
| | * Change syntax format for example returned valuesPrem Sichanugrist2013-11-111-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | According to our guideline, we leave 1 space between `#` and `=>`, so we want `# =>` instead of `#=>`. Thanks to @fxn for the suggestion. [ci skip]
| * | Fix ActiveRecord::Relation#unscopeJon Leighton2013-11-201-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm pretty confused about the addition of this method. The documentation says that it was intended to allow the removal of values from the default scope (in contrast to #except). However it behaves exactly the same as except: https://gist.github.com/jonleighton/7537008 (other than having a slightly enhanced syntax). The removal of the default scope is allowed by 94924dc32baf78f13e289172534c2e71c9c8cade, which was not a change we could make until 4.1 due to the need to deprecate things. However after that change #unscope still gives us nothing that #except doesn't already give us. However there *is* a desire to be able to unscope stuff in a way that persists across merges, which would allow associations to be defined which unscope stuff from the default scope of the associated model. E.g. has_many :comments, -> { unscope where: :trashed } So that's what this change implements. I've also corrected the documentation. I removed the guide references to #except as I think unscope really supercedes #except now. While we're here, there's also a potential desire to be able to write this: has_many :comments, -> { unscoped } However, it doesn't make sense and would not be straightforward to implement. While with #unscope we're specifying exactly what we want to be removed from the relation, with "unscoped" we're just saying that we want it to not have some things which were added earlier on by the default scope. However in the case of an association, we surely don't want *all* conditions to be removed, otherwise the above would just become "SELECT * FROM comments" with no foreign key constraint. To make the above work, we'd have to somehow tag the relation values which get added when evaluating the default scope in order to differentiate them from other relation values. Which is way too much complexity and therefore not worth it when most use cases can be satisfied with unscope. Closes #10643, #11061.
| * | use arel nodes to represent non-string `order_values`.Yves Senn2013-11-191-19/+11
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a bug when merging relations of different classes. ``` Given: Post.joins(:author).merge(Author.order(name: :desc)).to_sql Before: SELECT "posts".* FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY "posts"."name" DESC After: SELECT "posts".* FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY "authors"."name" DESC ```