aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/merger.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* select! renamed to avoid name collision Array#select!Earl J St Sauver2014-04-211-1/+9
| | | | | | | | 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!.
* Build the reverse_order on its proper method.Lauro Caetano2014-04-071-1/+0
| | | | | | | | | | | | | | | | | | 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"
* stuff the join dependency object in the "anything goes" hash.Aaron Patterson2013-10-101-1/+1
|
* Relation#merge should not lose readonly(false) flag.thedarkone2013-09-111-1/+5
| | | | The original code ignores the `false` value because `false.blank? # => true`.
* Don't create fibers just to iterateNicholas Jakobsen2013-08-301-3/+3
|
* add a specific factory method rather than using newAaron Patterson2013-07-231-1/+1
|
* reorder bind parameters when merging relationsAaron Patterson2013-07-151-2/+18
|
* Typo fix [skip ci]Ankit Gupta2013-07-121-1/+1
|
* Simplify/fix implementation of default scopesJon Leighton2013-06-281-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation was necessary in order to support stuff like: class Post < ActiveRecord::Base default_scope where(published: true) scope :ordered, order("created_at") end If we didn't evaluate the default scope at the last possible moment before sending the SQL to the database, it would become impossible to do: Post.unscoped.ordered This is because the default scope would already be bound up in the "ordered" scope, and therefore wouldn't be removed by the "Post.unscoped" part. In 4.0, we have deprecated all "eager" forms of scopes. So now you must write: class Post < ActiveRecord::Base default_scope { where(published: true) } scope :ordered, -> { order("created_at") } end This prevents the default scope getting bound up inside the "ordered" scope, which means we can now have a simpler/better/more natural implementation of default scoping. A knock on effect is that some things that didn't work properly now do. For example it was previously impossible to use #except to remove a part of the default scope, since the default scope was evaluated after the call to #except.
* avoid creating a set if no where values are removedAaron Patterson2013-05-211-0/+2
|
* remove bind values for where clauses that were removedAaron Patterson2013-05-211-9/+8
|
* push partitioning up so bind elimination can get the removed wheresAaron Patterson2013-05-211-5/+3
|
* push partion logic down and initialization logic upAaron Patterson2013-05-211-15/+11
|
* partition the where values so we can access the removed onesAaron Patterson2013-05-201-1/+6
|
* eliminate some conditionalsAaron Patterson2013-05-201-3/+3
|
* change method name to reflect what it actually does.Aaron Patterson2013-05-201-2/+2
|
* save the where values in variables so we don't need to look them up allAaron Patterson2013-05-201-4/+5
| | | | the time
* pass where values to the helper function rather than rely on internal stateAaron Patterson2013-05-201-4/+4
|
* Extract JoinDependency#join_relation to DRY the repeated application of the ↵Ben Woosley2013-05-101-3/+1
| | | | #join_associations.
* extracted piece of code into a methodNeeraj Singh2013-05-081-13/+12
| | | | | | | | | | | | | | | | In order to fix #10421 I need to enable merge to take an option so that relations could be merged without making the last where condition to win. That fix would forever reside in 4-0-stable branch and would not be merged to master since using scope without lambda has been deprecated. In this commit I have extracted code into a method and I think it makes code look better. Hence the request to merge it in both master and 4-0-stable. If there is any concern then this code can be merged only in 4-0-stable and that would be fine too.
* Remove warningCarlos Antonio da Silva2013-04-101-2/+2
| | | | warning: `*' interpreted as argument prefix
* While merging relations preserve context for joinsJared Armstrong and Neeraj Singh2013-04-101-2/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #3002. Also see #5494. ``` class Comment < ActiveRecord::Base belongs_to :post end class Author < ActiveRecord::Base has_many :posts end class Post < ActiveRecord::Base belongs_to :author has_many :comments end ``` `Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all` would fail with `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`. It is failing because `all` is being called on relation which looks like this after all the merging: `{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this relation all the context that `Post` was joined with `Author` is lost and hence the error that `author` was not found on `Comment`. Ths solution is to build JoinAssociation when two relations with join information are being merged. And later while building the arel use the previously built `JoinAssociation` record in `JoinDependency#graft` to build the right from clause. Thanks to Jared Armstrong (https://github.com/armstrjare) for most of the work. I ported it to make it compatible with new code base.
* Prevent Relation#merge from collapsing wheres on the RHSJon Leighton2013-01-271-17/+19
| | | | | | | | | | | | | | | | | | | | | | | This caused a bug with the new associations implementation, because now association conditions are represented as Arel nodes internally right up to when the whole thing gets turned to SQL. In Rails 3.2, association conditions get turned to raw SQL early on, which prevents Relation#merge from interfering. The current implementation was buggy when a default_scope existed on the target model, since we would basically end up doing: default_scope.merge(association_scope) If default_scope contained a where(foo: 'a') and association_scope contained a where(foo: 'b').where(foo: 'c') then the merger would see that the same column is representated on both sides of the merge and collapse the wheres to all but the last: where(foo: 'c') Now, the RHS of the merge is left alone. Fixes #8990
* performance improvements to joins!Aaron Patterson2012-10-121-2/+12
| | | | | | | | | | | | | | | | | | Before: Calculating ------------------------------------- ar 87 i/100ms ------------------------------------------------- ar 823.4 (±11.8%) i/s - 4089 in 5.070234s After: Calculating ------------------------------------- ar 88 i/100ms ------------------------------------------------- ar 894.1 (±3.9%) i/s - 4488 in 5.028161s Same test as 3a6dfca7f5f5bd45cea2f6ac348178e72423e1d5
* Speed up relation merging by reducing calls to Array#-Aaron Patterson2012-10-121-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | before: Calculating ------------------------------------- ar 83 i/100ms ------------------------------------------------- ar 832.1 (±4.0%) i/s - 4233 in 5.096611s after: Calculating ------------------------------------- ar 87 i/100ms ------------------------------------------------- ar 839.0 (±9.3%) i/s - 4176 in 5.032782s Benchmark: require 'config/environment' require 'benchmark/ips' GC.disable unless User.find_by_login('tater') u = User.new u.login = 'tater' u.save! end def active_record user = User.find_by_login('tater') starred = user.starred_items.count end active_record Benchmark.ips do |x| x.report("ar") { active_record } end
* Fix "last equality wins" logic in relation mergeErnie Miller2012-08-191-10/+5
| | | | | | This is a real fix (as compared to the band-aid in b127d86c), which uses the recently-added equality methods for ARel nodes. It has the side benefit of simplifying the merge code a bit.
* Fix merge error when Equality LHS is non-attributeErnie Miller2012-08-171-2/+5
| | | | | | | | | This is at best a band-aid for a more proper fix, since it won't truly handle the removal of the previous equality condition of these other nodes. I'm planning to put in some work on ARel toward supporting that goal. Related: rails/arel#130, ernie/squeel#153, ernie/squeel#156
* load active_support/core_ext/object/blank in active_support/railsXavier Noria2012-08-021-1/+0
|
* Add nodoc to HashMerger and MergerOscar Del Ben2012-07-171-2/+2
|
* Relation#from to accept other Relation objectsRadoslav Stankov2012-05-171-1/+2
| | | | Record.from("(#{sub_query.to_sql})") -> Record.from(sub_query) Record.from("(#{sub_query.to_sql}) a") -> Record.from(sub_query, :a)
* Revert "Merge pull request #5494 from ↵Jon Leighton2012-05-051-28/+3
| | | | | | | armstrjare/active_record_relation_keep_association_join_context_on_merge" This reverts commit dcd04e76179611a9db28c9e391aa7d6c2a5b046a, reversing changes made to 58a49875df63729f07a9a81d1ee349087d258df5.
* Allow ActiveRecord::Relation merges to maintain context of joined associationsJared Armstrong2012-05-041-3/+28
|
* fix interpolation for hash mergingJon Leighton2012-04-251-15/+24
|
* allow merging a single where valueJon Leighton2012-04-251-1/+1
|
* now we can just manipulate the values hash in #only and #exceptJon Leighton2012-04-131-10/+1
|
* remove apply_finder_options call from AssociationScopeJon Leighton2012-04-131-1/+1
|
* Make Relation#extending work like other value methodsJon Leighton2012-04-131-3/+1
|
* assert valid keysJon Leighton2012-04-131-0/+5
|
* Allow Relation#merge to take a hashJon Leighton2012-04-131-44/+69
|
* we have no need for the ASSOCIATION_METHODS constantJon Leighton2012-04-131-1/+1
|
* refactoringJon Leighton2012-04-131-36/+45
|
* Extract clusterfuck method for surgeryJon Leighton2012-04-131-0/+84