aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
...
* | | | Setting an association replaces records with the same id in memorySean Griffin2014-11-251-0/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The records weren't being replaced since equality in Active Record is defined in terms of `id` only. It is reasonable to expect that the references would be replaced in memory, even if no queries are actually executed. This change did not appear to affect any other parts of the code base. I chose not to execute callbacks since we're not actually modifying the association in a way that will be persisted. Fixes #17730
* | | | Fix includes on association with a scope containing joins along with conditionssiddharth@vinsol.com2014-11-211-0/+6
| | | | | | | | | | | | | | | | on the joined assoiciation
* | | | Merge pull request #17575 from shikshachauhan/make-habtm-consistentRafael Mendonça França2014-11-191-0/+10
|\ \ \ \ | | | | | | | | | | Allow class_name option in habtm to be consistent with other association...
| * | | | Allow habtm class_name option to be consistent with other associationsshiksha2014-11-131-0/+10
| | | | |
* | | | | Build fix when running in isolationArun Agrawal2014-11-147-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | `Computer` class needs to be require See #17217 for more details
* | | | | Merge pull request #11694 from ↵Rafael Mendonça França2014-11-101-0/+7
|\ \ \ \ \ | |/ / / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Empact/association-bind-values-not-updated-on-save Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id Conflicts: activerecord/CHANGELOG.md
| * | | | Fix that a collection proxy could be cached before the save of the owner, ↵Ben Woosley2014-10-031-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | resulting in an invalid proxy lacking the owner’s id. Absent this fix calls like: owner.association.update_all to behave unexpectedly because they try to act on association objects where owner_id is null. more evidence here: https://gist.github.com/Empact/5865555 ``` Active Record 3.2.13 -- create_table(:firms, {:force=>true}) -> 0.1371s -- create_table(:clients, {:force=>true}) -> 0.0005s 1 clients. 1 expected. 1 clients updated. 1 expected. ``` ``` Active Record 4.0.0 -- create_table(:firms, {:force=>true}) -> 0.1606s -- create_table(:clients, {:force=>true}) -> 0.0004s 1 clients. 1 expected. 0 clients updated. 1 expected. ```
* | | | | Ensure HABTM relationships produce valid class names (Fixes #17119)Sammy Larbi2014-11-091-1/+10
| | | | |
* | | | | default scopes should break the cache on singulur_association.alfa-jpn2014-11-081-0/+29
| | | | | | | | | | | | | | | | | | | | fixes #17495
* | | | | default scopes should break the cache on has_many.Aaron Patterson2014-11-071-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | if you specify a default scope on a model, it will break caching. We cannot predict what will happen inside the scope, so play it safe for now. fixes #17495
* | | | | copy reflection_scopes’s unscoped value when building scope for ↵Byron Bischoff2014-10-221-0/+8
| | | | | | | | | | | | | | | | | | | | preloading, fixes #11036
* | | | | Raise an error for has_one associations which try to go :through a ↵Tu Hoang2014-10-151-0/+6
| |_|_|/ |/| | | | | | | | | | | polymorphic association [#17263]
* | | | measure record instantiation time in AS::NotificationsAaron Patterson2014-10-131-0/+36
|/ / / | | | | | | | | | | | | emit an event when we instantiate AR objects so we can see how many records were instantiated and how long it took
* | | Replace drop sql statement to drop_table methodYasuo Honda2014-09-111-2/+2
| | | | | | | | | | | | to drop sequences at the same time each tables dropped for Oracle
* | | Do not mark object as persisted after an association is savedRafael Mendonça França2014-09-052-19/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Callback order in Active Record objects are important. Users should not define callbacks before the association definition or surprising behaviours like the described at #3798 will happen. This callback order dependency is documented at https://github.com/rails/rails/blob/31bfcdc77ca0d8cec9b5fe513bdc6f05814dd4f1/activerecord/lib/active_record/associations.rb#L1222-1227. This reverts #15728. Fixes #16620.
* | | Fixed regression with referencing polymorphic assoc in eager-loadGodfrey Chan2014-09-051-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is cased by 03118bc + 9b5d603. The first commit referenced the undefined local variable `column` when it should be using `reflection.type` as the lookup key. The second commit changed `build_arel` to not modify the `bind_values` in- place so we need to combine the arel's `bind_values` with the relation's when building the SQL. Fixes #16591 Related #15821 / #15892 / 7aeca50
* | | Remove 'if exists' from drop table statement then use `table_exists?`Yasuo Honda2014-09-031-2/+2
| | | | | | | | | | | | | | | Since 'drop table if exists' statement does not always work with some databases such as Oracle.
* | | Ignore SCHEMA queries when asserting no queriesAkira Matsuda2014-08-283-12/+12
| | |
* | | Ignore SCHEMA queries in some habtm testsAkira Matsuda2014-08-141-4/+4
| | |
* | | Make sure assertion passes for postgresql.Zuhao Wan2014-07-221-1/+1
| | |
* | | Merge pull request #15266 from dv/use_counter_cache_for_empty_callGodfrey Chan2014-07-151-0/+7
|\ \ \ | | | | | | | | If a counter_cache exists, use it for #empty?
| * | | If a counter_cache exists, use it for #empty?David Verhasselt2014-06-101-0/+7
| | | |
* | | | Include fixtures to prevent foreign key violation.Zuhao Wan2014-07-091-0/+2
| | | |
* | | | Warm up cache to prevent assertion failure.Zuhao Wan2014-07-081-0/+1
| | | |
* | | | Re-enable foriegn key tests on MySQLGodfrey Chan2014-07-051-2/+0
| | | | | | | | | | | | | | | | This reverts commit e84799d, e31104c and e6ca8e2
* | | | Add a `required` option to singular associationsSean Griffin2014-07-041-0/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In addition to defining the association, a `required` association will also have its presence validated. Before: ```ruby belongs_to :account validates_presence_of :account ``` After: ```ruby belongs_to :account, required: true ``` This helps to draw a distinction between types of validations, since validations on associations are generally for data integrity purposes, and aren't usually set through form inputs.
* | | | Do not change the global state of the test suiteRafael Mendonça França2014-06-271-18/+1
| | | |
* | | | Improve tests to use add_foreign_key DSLRafael Mendonça França2014-06-271-18/+11
| | | |
* | | | MySQL doesn't works with foreign keyRafael Mendonça França2014-06-271-3/+2
| | | |
* | | | Merge pull request #12450 from iantropov/masterRafael Mendonça França2014-06-271-0/+36
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix bug, when ':dependent => :destroy' violates foreign key constraints Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/builder/association.rb activerecord/lib/active_record/associations/builder/has_one.rb
| * | | | Fix bug, when ':dependent => :destroy' option violates foreign key ↵Ivan Antropov2013-10-261-0/+36
| | | | | | | | | | | | | | | | | | | | constraints, issue #12380
* | | | | Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-266-25/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* | | | | `preload` preserves readonly flag on associations. #15853Yves Senn2014-06-251-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a partial fix for #15853. It only works when a `preload` is issued and not an `eager_load`. I've added a skipped failing test-case to keep in mind that we need to deal with `eager_load`.
* | | | | Merge pull request #15728 from sgrif/sg-double-save-hm-tRafael Mendonça França2014-06-191-1/+20
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Don't save through records twice Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * | | | | Don't save through records twiceSean Griffin2014-06-171-0/+19
| | |_|/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | If the through record gets created in an `after_create` hook that is defined before the association is defined (therefore after its `after_create` hook) get saved twice. This ensures that the through records are created only once, regardless of the order of the hooks.
* | | | | Merge pull request #15747 from sgrif/sg-trolololol-this-is-so-brokenRafael Mendonça França2014-06-191-0/+30
|\ \ \ \ \ | | | | | | | | | | | | Always update counter caches in memory when adding records
| * | | | | Always update counter caches in memory when adding recordsSean Griffin2014-06-161-0/+30
| |/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before, calling `size` would only work if it skipped the cache, and would return a different result from the cache, but only if: - The association was previously loaded - Or you called size previously - But only if the size was 0 when you called it This ensures that the counter is appropriately updated in memory.
* | | | | Merge pull request #15772 from nbudin/sti_through_bugRafael Mendonça França2014-06-191-0/+8
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | Don't include inheritance column in the through_scope_attributes
| * | | | | Don't include inheritance column in the through_scope_attributesNat Budin2014-06-171-0/+8
| |/ / / /
* | | | | Use a better test descriptionRafael Mendonça França2014-06-191-1/+1
| | | | |
* | | | | Fix has_and_belongs_to_many in a namespaced model pointing to a non ↵Rafael Mendonça França2014-06-191-0/+9
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | namespaced model Now the following case will work fine class Tag < ActiveRecord::Base end class Publisher::Article < ActiveRecord::Base has_and_belongs_to_many :tags end Fixes #15761
* | | | Merge pull request #15343 from dontfidget/fix_polymorphic_automatic_inverse_ofRafael Mendonça França2014-06-131-0/+11
|\ \ \ \ | | | | | | | | | | prevent bad automatic inverse_of association
| * | | | use name specified by 'as' for automatic inverse association to avoid ↵Andrew S. Brown2014-06-101-0/+11
| | |_|/ | |/| | | | | | | | | | reflecting on wrong association
* | | | Through associations should set both parent ids on join modelsSean Griffin2014-06-132-0/+27
| |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | member = Member.new(club: Club.new) member.save! Before: member.current_membership.club_id # => nil After: member.current_membership.club_id # => club's id
* | | Fix inverse associations testLeandro Facchinetti2014-06-041-1/+1
| | | | | | | | | | | | | | | | | | `InverseHasManyTests#test_parent_instance_should_be_shared_within_create_block_of_new_child` was mistakenly the same as `InverseHasManyTests#test_parent_instance_should_be_shared_within_build_block_of_new_child`.
* | | Fix regression on eager loading association based on SQL query ratherLauro Caetano2014-06-031-0/+4
| | | | | | | | | | | | | | | | | | than existing column. Fixes #15480.
* | | just use `assert`Aaron Patterson2014-06-021-1/+1
| | |
* | | Merge pull request #14834 from al2o3cr/issue14155Aaron Patterson2014-05-271-0/+10
|\ \ \ | | | | | | | | Correctly alias table names when joining more than once
| * | | WIP: pass existing joins to construct_join_dependencyMatt Jones2014-05-161-0/+10
| | | |
* | | | Fix redefine a has_and_belongs_to_many inside inherited classArthur Neves2014-05-271-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After ad7b5efb55bcc2e0ccd3e7f22a81e984df8676d1, which changed how has_an_belongs_to_many used to work, we start raising an error when redefining the same has_an_belongs_to_many association. This commits fix that regression. [Fixes #14983]