aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Merge pull request #13340 from akshay-vishnoi/typoGodfrey Chan2013-12-181-5/+4
|\ | | | | #none documentation updated [ci skip]
| * #none documentation updated [ci skip]Akshay Vishnoi2013-12-181-5/+4
| |
* | Create a blacklist to disallow mutator methods to be delegated to `Array`.Lauro Caetano2013-12-171-11/+14
| | | | | | | | | | | | | | | | This change was necessary because the whitelist wouldn't work. It would be painful for users trying to update their applications. This blacklist intent to prevent odd bugs and confusion in code that call mutator methods directely on the `Relation`.
* | Better support for `where()` conditions that use an association name.Martin Emde2013-12-161-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using the name of an association in `where` previously worked only if the value was a single `ActiveRecrd::Base` object. e.g. Post.where(author: Author.first) Any other values, including `nil`, would cause invalid SQL to be generated. This change supports arguments in the `where` query conditions where the key is a `belongs_to` association name and the value is `nil`, an `Array` of `ActiveRecord::Base` objects, or an `ActiveRecord::Relation` object. # Given the Post model class Post < ActiveRecord::Base belongs_to :author end # nil value finds records where the association is not set Post.where(author: nil) # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL # Array values find records where the association foreign key # matches the ids of the passed ActiveRecord models, resulting # in the same query as Post.where(author_id: [1,2]) authors_array = [Author.find(1), Author.find(2)] Post.where(author: authors_array) # ActiveRecord::Relation values find records using the same # query as Post.where(author_id: Author.where(last_name: "Emde")) Post.where(author: Author.where(last_name: "Emde")) Polymorphic `belongs_to` associations will continue to be handled appropriately, with the polymorphic `association_type` field added to the query to match the base class of the value. This feature previously only worked when the value was a single `ActveRecord::Base`. class Post < ActiveRecord::Base belongs_to :author, polymorphic: true end Post.where(author: Author.where(last_name: "Emde")) # Generates a query similar to: Post.where(author_id: Author.where(last_name: "Emde"), author_type: "Author")
* | Merge pull request #13307 from akshay-vishnoi/typoRafael Mendonça França2013-12-151-2/+2
|\| | | | | Spelling and Grammar check [ci skip]
| * Spelling and Grammar check [ci skip]Akshay Vishnoi2013-12-161-2/+2
| |
* | argument prefix warning removedArun Agrawal2013-12-131-1/+1
| | | | | | | | * interpreted as a argument prefix
* | Add a bunch of Relation -> Array delegate methods to the whitelist. This ↵Jeremy Kemper2013-12-121-4/+12
| | | | | | | | won't last - aim to switch back to a blacklist for mutator methods.
* | Use `public_send` instead of just use `send`.Lauro Caetano2013-12-121-5/+5
| |
* | Use a whitelist to delegate methods to arrayLauro Caetano2013-12-121-18/+6
|/
* Mark the arguments needed by activerecord-deprecated_finders with a TODORafael Mendonça França2013-12-111-0/+12
|
* Revert "Merge pull request #12518 from vipulnsward/remove_count_options"Rafael Mendonça França2013-12-111-12/+13
| | | | | | | It is needed for activerecord-depecated_finders This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
* Fix type cast on group sum with custom expressionPaul Nikitochkin2013-12-101-1/+3
| | | | | | | | For PG adapters with custom expression and grouped result of aggregate functions have not found correct column type for it. Extract column type from query result. Closes: #13230
* Fix offset with last.Lauro Caetano2013-12-031-1/+1
| | | | Closes #7441
* 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 ```
* | document id prefixed String usage of `.find`. refs #12891 [ci skip]Yves Senn2013-11-151-5/+6
|/
* Added ActiveRecord::QueryMethods#rewhere which will overwrite an existing, ↵David Heinemeier Hansson2013-11-021-0/+12
| | | | named where condition.
* unscope now works on default_scope after ↵Rafael Mendonça França2013-11-021-3/+0
| | | | 94924dc32baf78f13e289172534c2e71c9c8cade
* Merge branch 'master' into joindepAaron Patterson2013-10-212-1/+10
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (23 commits) Escape the parentheses in the default function regexp Update docs on Tilt::Template in Asset Pipeline guide Fix loading a sql structure file on postgres when the file's path has whitespace in it remove trailing whitespace added with b057765 [ci skip]. Allow unscope to work with `where.not` Raise an exception when model without primary key calls .find_with_ids Process sub-query relation's binding values Instrument the generation of Action Mailer messages Remove extra variable creation and merge. In Relation#empty? use #exists? instead of #count. [ci skip] avoid deprecation warning in sample code Convert Fixnum into String the port number in MySQL Fix some indentation on autosave association Make define_non_cyclic_method simpler Add Sass gobbling info to asset pipeline docs Ensure the state is clean after one failure Fix typo in form_helper.rb add a new local variable to track if digests are being stored, to ensure the cleanup works correctly [ci skip] Fix number of methods added by association. update digestor code based on review ...
| * Merge pull request #12588 from jetthoughts/12586_subquery_with_unprepared_sqlRafael Mendonça França2013-10-211-0/+7
| |\ | | | | | | | | | | | | | | | | | | Inline bind values for sub-queries generated for Relation in where Conflicts: activerecord/CHANGELOG.md
| | * Process sub-query relation's binding valuesPaul Nikitochkin2013-10-201-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | Generated sub-query for Relation as array condition for `where` method did not take in account its bind values, in result generates invalid SQL query. Fixed by adding sub-query relation's binding values to base relation Closes: #12586
| * | Allow unscope to work with `where.not`Eric Hankins2013-10-211-1/+1
| | | | | | | | | | | | | | | | | | Allows you to call #unscope on a relation with negative equality operators, i.e. Arel::Nodes::NotIn and Arel::Nodes::NotEqual that have been generated through the use of where.not.
| * | Raise an exception when model without primary key calls .find_with_idsShimpei Makimoto2013-10-211-0/+2
| |/
| * Don't remove the select values to add they back againRafael Mendonça França2013-10-151-1/+1
| | | | | | | | | | Conflicts: activerecord/lib/active_record/relation/finder_methods.rb
* | pass the outer joins to join_constraintsAaron Patterson2013-10-201-5/+1
| |
* | Merge branch 'master' into joindepAaron Patterson2013-10-152-15/+13
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (44 commits) grammar fix (reverted in e9a1ecd) Revert "fixed a doc bug in the CHANGELOG.md s/does no longer depend on/no longer depends on/" Add missed require making `enable_warnings` available Prepare generated Gemfile for Capistrano 3 Added --model-name option scaffold_controller_generator. read the association instead of sending we should have unique sponsorable ids in the fixtures at least simplify populating the ordering hash the preloader for the RHS has all the preloaded records, so ask it only calculate offset index once. #12537 Remove size alias for length validation Fix `singleton_class?` Minor Refactoring to `NumberHelper#number_to_human` `$SAFE = 4;` has been removed with Ruby 2.1 scope_chain should not be mutated for other reflections Remove `default_primary_key_type` and extract contains of `native_database_types` to a constant since they aren't conditional now in SQLite3Adapter. Makes it more like other adapters. cleanup changelog entry format. [ci skip] Extract a function to determine if the default value is a function Push default_function to superclass to avoid method check Dump the default function when the primary key is uuid ... Conflicts: activerecord/lib/active_record/relation/finder_methods.rb
| * Stop accepting `options` for `Relation#average`, `Relation#minimum`, ↵Vipul A M2013-10-141-10/+10
| | | | | | | | `Relation#maximum`, `Relation#calculate`, `perform_calculation`, `NullRelation#calculate` as they isn't used anymore.
| * `Relation#count` doesn't use options anymore.Vipul A M2013-10-131-3/+2
| |
| * Merge pull request #11791 from versioncontrol/includes_with_persistent_selectRafael Mendonça França2013-10-121-1/+1
| |\ | | | | | | Includes with persistent select, fixes #11773
| | * Fixes #11773 when using includes combined with select, the select statement ↵Edo Balvers2013-10-081-1/+1
| | | | | | | | | | | | was overwritten.
* | | keep a cache on the alias objectAaron Patterson2013-10-141-1/+1
| | |
* | | store aliases in a better structureAaron Patterson2013-10-141-1/+3
| | |
* | | eliminate single use methodAaron Patterson2013-10-131-6/+3
| | |
* | | eliminate duplicate code from to_sqlAaron Patterson2013-10-131-4/+8
| | | | | | | | | | | | I don't really like passing the block, but this seems easiest for now
* | | calling construct_relation_for_association_find is no longer necessaryAaron Patterson2013-10-131-1/+1
| | |
* | | push up `select` exclusionAaron Patterson2013-10-131-3/+4
| | |
* | | JoinDependency will take care of making things uniqueAaron Patterson2013-10-131-1/+1
|/ /
* | merge JoinDependency as outer joinsAaron Patterson2013-10-101-1/+1
| | | | | | | | Merge JoinDependency objects as outer joins
* | stuff the join dependency object in the "anything goes" hash.Aaron Patterson2013-10-103-4/+6
| |
* | stop splatting things back and forthAaron Patterson2013-10-101-1/+1
| |
* | hide join_constraints inside the JoinDependency objectAaron Patterson2013-10-091-2/+1
|/
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2013-09-281-1/+1
|\
| * `skiping` => `skipping`Vipul A M2013-09-171-1/+1
| |
* | Merge pull request #12011 from jetthoughts/11963_fix_join_with_association_scopeRafael Mendonça França2013-09-161-6/+5
|\ \ | | | | | | | | | | | | | | | | | | Collapse where constraints to the Arel::Nodes::And node Conflicts: activerecord/CHANGELOG.md
| * | Collapse where constraints to one where constraintPaul Nikitochkin2013-09-131-6/+5
| | | | | | | | | | | | | | | | | | | | | In order to remove duplication with joining arel where constraints with `AND`, all constraints on `build_arel` are collapsed into one head node: `Arel::Nodes::And` Closes: #11963