aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/alias_tracker.rb
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* The AliasTracker#aliased_table_for needs the type caster for the joined ↵Ray Zane2017-06-251-10/+9
| | | | association, not the join root
* Don't expose methods and attrs for internal usageRyuta Kamizono2017-05-301-2/+5
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* no more class methods for JoinDependency [ci skip]Gaurav Sharma2015-09-291-2/+1
| | | `ActiveRecord::Associations::JoinDependency` now it’s own class` and `ActiveRecord::Associations::ThroughAssociationScope` doesn’t exists
* Move `#type_caster` to alias tracker initializeeileencodes2015-01-021-6/+7
| | | | | This moves the `#type_caster` from the `aliased_table_for` and into the initialize of the `alias_tracker`.
* Initialze `#alias_tracker` with base table nameeileencodes2015-01-021-8/+11
| | | | | | | Instead of initializing an empty connection use the base table name instead. Split up and refactor `#create` to be 2 methods `#create` and `#create_with_joins`. Removes the need to update the count by 1 on initialzing a JoinDependency.
* Pass `connection` rather than `alias_tracker`eileencodes2015-01-021-3/+3
| | | | | | | | | After the refactorings we're only using the connection and not the alias tracker anymore. This builds on commit 18019. Reuse the already available `@connection` to reduce the surface area of the alias tracker's API. We can then remove the `attr_reader` because the connection is already available.
* Pass a type caster when aliasing tables for joinsSean Griffin2014-12-291-3/+3
|
* Combine aliased_table_for and aliased_name_foreileencodes2014-11-241-12/+3
| | | | | | | | | This refactoring reduces the number of conditionals needed to build `aliased_table_for` and removes `aliased_name_for` because it's no longer necessary. `aliased_name_for` was also used in `JoinDependency#initialize` so that was replaced with `aliased_table_for` as well.
* WIP: pass existing joins to construct_join_dependencyMatt Jones2014-05-161-1/+11
|
* add factory methods for empty alias trackersAaron Patterson2014-02-141-21/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-4/+2
|
* stop exposing table_joinsAaron Patterson2014-02-141-4/+3
|
* make most parameters to the AliasTracker requiredAaron Patterson2014-02-141-5/+3
| | | | | This helps with our sanity. The class is internal, we can refactor to a "nice" API later.
* Remove ActiveRecord::ModelJon Leighton2012-10-261-1/+1
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* fix associations when using per class databasesLars Kanis2012-02-101-6/+3
| | | | | | 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
* The join_nodes must be passed to the JoinDependency initializer and ↵Jon Leighton2011-08-291-6/+12
| | | | therefore counted by the alias tracker. This is because the association_joins are aliased on initialization and then the tables are cached, so it is no use to alias the join_nodes later. Fixes #2556.
* a few minor performance improvements: fewer strings, fewer range objects, ↵Aaron Patterson2011-07-011-20/+12
| | | | fewer method calls
* remove unused codesAaron Patterson2011-07-011-4/+0
|
* AliasTracker.pluralize use pluralize_table_names of modelGuillermo Iguaran2011-05-201-2/+2
|
* Fixing has_many association when ActiveRecord::Base.pluralize_table_names is ↵Guillermo Iguaran2011-05-151-1/+1
| | | | false. fixes #557
* Resolve some TODO comments which I decided did not need anything doneJon Leighton2011-03-121-1/+1
|
* Merge branch 'master' into nested_has_many_throughJon Leighton2011-03-041-24/+28
| | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/associations/class_methods/join_dependency.rb activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb activerecord/lib/active_record/associations/has_many_association.rb activerecord/lib/active_record/associations/has_many_through_association.rb activerecord/lib/active_record/associations/has_one_association.rb activerecord/lib/active_record/associations/has_one_through_association.rb activerecord/lib/active_record/associations/through_association_scope.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/associations/has_many_through_associations_test.rb activerecord/test/cases/associations/has_one_through_associations_test.rb activerecord/test/cases/reflection_test.rb activerecord/test/cases/relations_test.rb activerecord/test/fixtures/memberships.yml activerecord/test/models/categorization.rb activerecord/test/models/category.rb activerecord/test/models/member.rb activerecord/test/models/reference.rb activerecord/test/models/tagging.rb
* Merge branch 'master' into nested_has_many_throughJon Leighton2010-12-121-13/+21
| | | | | | | | Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/associations/class_methods/join_dependency.rb activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb activerecord/lib/active_record/associations/has_many_through_association.rb
* Fix naughty trailing whitespaceJon Leighton2010-10-311-13/+13
|
* Some small tweaks on the last commitJon Leighton2010-10-121-2/+7
|
* Extract aliasing code from JoinDependency and JoinAssociation into a ↵Jon Leighton2010-10-121-0/+68
separate AliasTracker class. This can then be used by ThroughAssociationScope as well.