aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* remove check for present? from delete_alleileencodes2014-04-071-2/+2
| | | | | Passing in a blank string is a bug so there's no reason to check for a blank string.
* fix CollectionProxy delete_all documentationeileencodes2014-04-061-6/+1
| | | | | | | This method no longer returns an array of all records that have been removed. Correct documentation to reflect this change. See issue 14546
* Merge pull request #11650 from prathamesh-sonpatki/renameRafael Mendonça França2014-04-042-7/+7
|\ | | | | | | Renamed private methods _create_record and _update_record
| * [Active Record] Renamed private methods create_record and update_recordPrathamesh Sonpatki2014-02-202-7/+7
| | | | | | | | | | | | This is to ensure that they are not accidentally called by the app code. They are renamed to _create_record and _update_record respectively. Closes #11645
* | CollectionProxy uses the arel of its association's scope.Jefferson Lai2014-04-021-0/+4
| | | | | | | | | | | | CollectionProxy should be able to reuse the behavior (methods) of its parent class, but with its own state. This change allows CollectionProxy to use the arel object corresponding to its association's scope.
* | Merge pull request #14546 from ↵Aaron Patterson2014-03-311-1/+1
|\ \ | | | | | | | | | | | | eileencodes/fix_delete_all_to_not_use_IN_statement Fix delete all to not produce sql in statement
| * | fix delete_all to remove records directlyeileencodes2014-03-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When delete_all is run on a CollectionProxy and has a dependency of delete_all the SQL that is produced has an IN statement. (DELETE FROM `associated_model` where `associated_model` .`parent_id` = 1 AND `associated_model`.`id` IN (1, 2, 3...)). This only happens if the association is not loaded (both loaded and non-loaded delete_all should behave the same. This is a huge problem when it comes to deleting many records because the query becomes very slow. Instead the SQL produced should be (DELETE FROM `assoicated_model` where `associated_model`.`parent_model_id`=1). I fixed this by making sure the check for loaded and destroy also makes sure that the dependent is not delete_all, so the conditional goes to the else and deletes the records directly without the IN statement.
* | | Simplify Preloader#grouped_records code.thedarkone2014-03-301-20/+6
| | | | | | | | | | | | | | | | | | The new method relies on AR::Associations::Association knowing about both reflection and a model class. AR::Base#association now raises a descriptive error when trying to access non-existent associations. Previously it would blow up with a confusing NoMethodError: undefined method `association_class' for nil:NilClass.
* | | Fix polymorphic preloads on NOT NULL _type columns.thedarkone2014-03-301-10/+1
|/ / | | | | | | Defer to Association#klass instead of having a custom/duplicate code.
* | Merge pull request #14154 from al2o3cr/issue12770Aaron Patterson2014-03-271-1/+1
|\ \ | | | | | | Pass a base relation to build_default_scope when joining
| * | Pass a base relation to build_default_scope when joiningMatt Jones2014-02-211-1/+1
| | | | | | | | | | | | | | | This allows the default scope to be built using the current table alias. Resolves #12770
* | | Avoid duplicated conditionalsCarlos Antonio da Silva2014-03-141-2/+1
| | |
* | | passing an ActiveRecord object to `exists?` is deprecated.Aaron Patterson2014-03-131-1/+1
| | | | | | | | | | | | | | | Pass the id of the object to the method by calling `.id` on the AR object.
* | | make tests pass on Ruby 2.2Aaron Patterson2014-03-131-4/+4
| | | | | | | | | | | | | | | | | | Apparently we've been using a buggy feature for the past 6 years: https://bugs.ruby-lang.org/issues/9593
* | | Replace map.flatten with flat_map in activerecordErik Michaels-Ober2014-03-031-1/+1
| | |
* | | Remove unnecessary db call when replacing.Arthur Neves2014-02-281-1/+3
| | | | | | | | | | | | | | | | | | | | | When replacing a has_many association with the same one, there is no need to do a round-trip to the db to create/and drop a new transaction. [fixes #14220]
* | | let `insert_record` actuall save the object.Aaron Patterson2014-02-252-4/+3
|/ / | | | | | | | | | | | | | | | | | | `before_add` callbacks are fired before the record is saved on `has_and_belongs_to_many` assocations *and* on `has_many :through` associations. Before this change, `before_add` callbacks would be fired before the record was saved on `has_and_belongs_to_many` associations, but *not* on `has_many :through` associations. Fixes #14144
* | Prevent foreign_key_for? from type casting all attributesWojtek Kruszewski2014-02-211-1/+1
| |
* | Revert "speed up the collection proxy reader method, but slow down the ↵Arthur Neves2014-02-201-5/+1
|/ | | | | | | | constructor" This reverts commit f9e4c3c7c0c4152b62fe9202a9d12262884bb118. [fixes #14116]
* add factory methods for empty alias trackersAaron Patterson2014-02-143-23/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-142-5/+3
|
* stop exposing table_joinsAaron Patterson2014-02-141-4/+3
|
* make most parameters to the AliasTracker requiredAaron Patterson2014-02-142-6/+4
| | | | | This helps with our sanity. The class is internal, we can refactor to a "nice" API later.
* make a singleton for AssociationScopeAaron Patterson2014-02-142-1/+7
| | | | | 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-142-9/+3
|
* 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-132-41/+25
|
* speed up the collection proxy reader method, but slow down the constructorAaron Patterson2014-02-131-1/+5
|
* Dont use Enumarator on join_associationArthur Neves2014-02-131-2/+4
|
* Avoid using deprecated arel constantsRafael Mendonça França2014-02-102-3/+3
|
* Merge pull request #13899 from ↵Rafael Mendonça França2014-02-041-1/+1
|\ | | | | | | | | Fortisque/kevin/active_record_HABTM_with_belongs_to destruction errors out on HABTM w/out primary key
| * fix HABTM w/out primary key errors on destructionKevin Casey2014-02-021-1/+1
| |
* | this class depends on JoinHelper, so we should require itAaron Patterson2014-01-311-0/+2
|/
* Associations now raise `ArgumentError` on name conflicts.Lauro Caetano2014-01-311-0/+6
| | | | | Dangerous association names conflicts include instance or class methods already defined by `ActiveRecord::Base`.
* Make CollectionProxy#reset return selfRafael Mendonça França2014-01-221-1/+2
|
* Calling reset on a collection association should unload the assocationKelsey Schlarman2014-01-211-0/+21
| | | | Need to define #reset on CollectionProxy.
* Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-212-5/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
* add missing information for `id` field when used with `select` [ci skip]Kuldeep Aggarwal2014-01-221-1/+1
|
* `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.Rafael Mendonça França2014-01-211-1/+1
| | | | | | | | | | Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results among different database engines. But for singular associations this behavior is not needed since we will have one record to return. As this ORDER BY option can lead some performance issues we are removing it for singular associations accessors. Fixes #12623.
* directly create the ARel ASTAaron Patterson2014-01-141-6/+4
| | | | rather than allocating a new Relation, just make the AST directly
* Change all "can not"s to the correct "cannot".T.J. Schuck2014-01-031-1/+1
|
* Merge pull request #10134 from ↵Rafael Mendonça França2014-01-032-5/+5
|\ | | | | | | | | derikson/collection_proxy_select_with_multiple_args Change CollectionProxy#select to take the same arguments as ActiveRecord::select