aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_scope.rb
Commit message (Collapse)AuthorAgeFilesLines
* begin refactoring add_constraints by moving join keyseileencodes2014-06-101-12/+3
| | | | | | | | | | | | | | add_constraints is complicated and difficult to read. This is the beginning of a long process of refactoring this code. First step: moved the join keys out of AssociationScope and into reflection. We then don't need to call `reflection` because now reflection is `self`. `foreign_key` must be named something else because reflection already has a `foreign_key` method and when passed into `JoinKeys` it was getting the wrong assignment. `reflection_foreign_key` seemed to be an appropriate name. I also named `key` `reflection_key` to match `reflection_foreign_key`.
* fix polymorphic? method and reuse iteileencodes2014-06-021-1/+1
| | | | | | Fix polymorphic to check for `options[:polymorphic]` instead of `options.key? :polymorphic` and then reuse the method `polymorphic?` method instead of constantly checking the same `options[:polymorphic]`.
* Refactor AssociationScope#get_bind_valuesEric Chahin2014-05-051-8/+1
| | | | Added #join_id_for(owner) to reflection to avoid accessing the source_macro
* cache scope building on associationsAaron Patterson2014-04-141-6/+49
| | | | SQL statements for querying associations are now cached
* Merge branch 'master' into adequaterecordAaron Patterson2014-02-171-31/+56
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
| * add factory methods for empty alias trackersAaron Patterson2014-02-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we know the alias tracker is empty, we can create one that doesn't use a hash with default block for counting. ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Schema.define do create_table :posts, force: true do |t| t.integer :comments_count end create_table :comments, force: true do |t| t.integer :post_id end end class Post < ActiveRecord::Base; has_many :comments; end class Comment < ActiveRecord::Base; belongs_to :post, counter_cache: true; end 10.times { Comment.create!(post: Post.create!) } record = Post.first association_name = :comments Benchmark.ips do |x| reflection = record.class.reflect_on_association(association_name) association = reflection.association_class.new(record, reflection) x.report('assoc') do reflection.association_class.new(record, reflection) end x.report('reader') do association.reader;nil end x.report('combined') do reflection.association_class.new(record, reflection).reader;nil end end [aaron@higgins rails (tracker)]$ TEST=ips bundle exec ruby ../1bb5456b5e035343df9d/gistfile1.rb -- create_table(:posts, {:force=>true}) -> 0.0062s -- create_table(:comments, {:force=>true}) -> 0.0003s Calculating ------------------------------------- assoc 833 i/100ms reader 28703 i/100ms combined 839 i/100ms ------------------------------------------------- assoc 9010.3 (±3.8%) i/s - 44982 in 5.000022s reader 3214523.4 (±5.5%) i/s - 16016274 in 5.001136s combined 8841.0 (±5.8%) i/s - 44467 in 5.049269s [aaron@higgins rails (tracker)]$ TEST=ips bundle exec ruby ../1bb5456b5e035343df9d/gistfile1.rb -- create_table(:posts, {:force=>true}) -> 0.0060s -- create_table(:comments, {:force=>true}) -> 0.0003s Calculating ------------------------------------- assoc 888 i/100ms reader 29217 i/100ms combined 900 i/100ms ------------------------------------------------- assoc 9674.3 (±3.3%) i/s - 48840 in 5.054022s reader 2988474.8 (±6.9%) i/s - 14842236 in 4.998230s combined 9674.0 (±3.1%) i/s - 48600 in 5.028694s
| * guarantee a list in the alias tracker so we can remove a conditionalAaron Patterson2014-02-141-1/+1
| |
| * make a singleton for AssociationScopeAaron Patterson2014-02-141-0/+6
| | | | | | | | | | AssociationScope no longer maintains state, so we're safe to keep a singleton and save on GC time
| * pass the association and connection to the scope methodAaron Patterson2014-02-141-8/+2
| |
| * pass the tracker down the stack and construct it in the scope methodAaron Patterson2014-02-141-18/+18
| |
| * clean up add_constraints signatureAaron Patterson2014-02-141-8/+9
| |
| * remove the reflection delegateAaron Patterson2014-02-141-15/+14
| |
| * remove klass delegatorAaron Patterson2014-02-141-10/+11
| |
| * remove chain delegateAaron Patterson2014-02-141-5/+6
| |
| * remove scope_chain delegateAaron Patterson2014-02-141-3/+3
| |
| * remove more delegate methodsAaron Patterson2014-02-131-7/+9
| |
| * :scissors: whitespaceAaron Patterson2014-02-131-1/+0
| |
| * rm delegate methods that are not actually usedAaron Patterson2014-02-131-2/+2
| |
| * JoinHelper is never reused, so there is no need to separateAaron Patterson2014-02-131-5/+25
| |
| * this class depends on JoinHelper, so we should require itAaron Patterson2014-01-311-0/+2
| |
* | Merge branch 'master' into set_bindsAaron Patterson2014-01-111-18/+12
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
| * Skip `include_values` from through associations chains for building target scopePaul Nikitochkin2013-10-271-2/+6
| | | | | | | | Fixes: #12242, #9517, #10240
| * remove HABTM special cases from associations classesAaron Patterson2013-10-021-12/+0
| |
| * use bind values for model typesAaron Patterson2013-07-311-2/+3
| |
| * only calculate the klass onceAaron Patterson2013-07-291-1/+2
| |
| * use the superclass implementationAaron Patterson2013-07-181-1/+1
| |
| * bind values should not be merged between scopesAaron Patterson2013-06-111-1/+1
| |
* | push binds through relation objectsAaron Patterson2013-05-201-0/+1
|/
* use | to have more intent revealing codeNeeraj Singh2013-04-041-1/+1
| | | | thanks to @egilburg for suggestion
* has_many through obeys order on through associationNeeraj Singh2013-04-041-0/+1
| | | | fixes #10016
* hide more data in the schema cacheAaron Patterson2013-03-141-1/+1
|
* Prevent Relation#merge from collapsing wheres on the RHSJon Leighton2013-01-271-4/+8
| | | | | | | | | | | | | | | | | | | | | | | 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
* Undeprecate the :extend optionJon Leighton2013-01-181-0/+1
| | | | | | | Suggested by @dhh. It doesn't affect the generated SQL, so seems reasonable to continue to allow it as an association option.
* Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-011-1/+1
| | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-201-1/+1
|
* fix association :extend optionJon Leighton2012-07-131-6/+2
|
* Represent association scope options as AR::Relations insternally.Jon Leighton2012-07-131-40/+15
|
* predicate builder should not recurse for determining where columns.Aaron Patterson2012-05-301-2/+17
| | | | | | Thanks to Ben Murphy for reporting this CVE-2012-2661
* remove apply_finder_options call from AssociationScopeJon Leighton2012-04-131-7/+8
|
* Revert "only mutate the scope object in the `bind` method"Aaron Patterson2012-02-271-1/+1
| | | | This reverts commit 1b9e19cd22f2b5d5e7b82e042f92340822c0f966.
* only mutate the scope object in the `bind` methodAaron Patterson2012-02-271-1/+1
|
* bind value creation refactoringAaron Patterson2012-02-271-4/+10
|
* removing dead codeAaron Patterson2012-02-271-3/+2
|
* use bind values for join columnsAaron Patterson2012-02-271-1/+16
|
* fix associations when using per class databasesLars Kanis2012-02-101-1/+1
| | | | | | would get ConnectionNotEstablished error because it always tried to use ActiveRecord::Base's connection, even though it should be using the connection of the model whose context we're operating in
* Deprecate inferred JOINs with includes + SQL snippets.Jon Leighton2012-01-161-1/+1
| | | | | | See the CHANGELOG for details. Fixes #950.
* Avoid sanitize_sql when we can use Relation#where insteadJon Leighton2012-01-161-2/+5
|
* Revert "Deprecate implicit eager loading. Closes #950."Jon Leighton2012-01-161-1/+1
| | | | This reverts commit c99d507fccca2e9e4d12e49b4387e007c5481ae9.
* Remove Array.wrap calls in ActiveRecordRafael Mendonça França2012-01-061-1/+1
|
* Deprecate implicit eager loading. Closes #950.Jon Leighton2011-12-291-1/+1
|