aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* Fix intermittent CI failure due to setting explicit `person.id = 10`Ryuta Kamizono2018-03-301-4/+0
| | | | https://travis-ci.org/rails/rails/jobs/360109429
* Don't unset foreign key when preloading missing recordEugene Kenny2018-03-241-0/+2
| | | | | | | | | When a belongs to association's target is set, its foreign key is now updated to match the new target. This is the correct behaviour when a new record is assigned, but not when the existing record is preloaded. As long as we mark the association as loaded, we can skip setting the target when the record is missing and avoid clobbering the foreign key.
* Fix dependence on has_one/belongs_to relationshipsFernando Gorodscy2018-03-062-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | When a class has a belongs_to or has_one relationship with dependent: :destroy option enabled, objects of this class should not be deleted if it's dependents cannot be deleted. Example: class Parent has_one :child, dependent: :destroy end class Child belongs_to :parent, inverse_of: :child before_destroy { throw :abort } end c = Child.create p = Parent.create(child: c) p.destroy p.destroyed? # expected: false; actual: true; Fixes #32022
* Eager loading with polymorphic associations should behave consistentlyRyuta Kamizono2018-03-041-2/+4
| | | | | | | | | | This reverts ignoring polymorphic error introduced at 02da8ae. What the ignoring want to solve was caused by force eager loading regardless of whether it is necessary, but it has been fixed by #29043. The ignoring is now only causing a mismatch of `exists?` behavior with `to_a`, `count`, etc. It should behave consistently.
* Extract all `base_class.name` as `polymorphic_name`Ryuta Kamizono2018-03-041-9/+23
| | | | | | | This is an alternative of #29722, and follow up of #32048. This does not change the current behavior, but makes it easier to modify all polymorphic names consistently.
* Fix "NameError: uninitialized constant Categorization::Category"yuuji.yaginuma2018-02-261-0/+1
| | | | | | | | Since #31895, build of 2.5 and AR combination failed. https://travis-ci.org/rails/rails/jobs/346064349#L1638 It seems to be the reason that model is not loading properly, so I added require. But I'm not sure if this is correct
* Merge pull request #31895 from ↵Ryuta Kamizono2018-02-261-0/+10
|\ | | | | | | | | kamipo/do_not_attempt_to_find_inverse_of_polymorphic Make `reflection.klass` raise if `polymorphic?` not to be misused
| * Make `reflection.klass` raise if `polymorphic?` not to be misusedRyuta Kamizono2018-02-191-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an alternative of #31877 to fix #31876 caused by #28808. This issue was caused by a combination of several loose implementation. * finding automatic inverse association of polymorphic without context (caused by #28808) * returning `klass` even if `polymorphic?` (exists before #28808) * loose verification by `valid_inverse_reflection?` (exists before #28808) This makes `klass` raise if `polymorphic?` not to be misused. This issue will not happen unless polymorphic `klass` is misused. Fixes #31876. Closes #31877.
* | Association creation and finding should work consistently (#32048)Ryuta Kamizono2018-02-261-5/+35
|/ | | | | | | | | | | This is an alternative of #29722, and revert of #29601 and a1fcbd9. Currently, association creation and normal association finding doesn't respect `store_full_sti_class`. But eager loading and preloading respect the setting. This means that if set `store_full_sti_class = false` (`true` by default), eager loading and preloading can not find created polymorphic records. Association creation and finding should work consistently.
* Association scope's own order should be prioritized over through scope's orderRyuta Kamizono2018-02-181-0/+7
| | | | | | | | | | 3acc5d6 was changed the order of scope evaluation from through scope to the association's own scope to be prioritized over the through scope. But the sorting order will be prioritized that is evaluated first. It is unintentional effect, association scope's sorting order should be prioritized as well. Fixes #32008.
* Deprecate update_attributes and update_attributes!Eddie Lebow2018-02-172-7/+7
| | | | Closes #31998
* Merge pull request #31934 from fatkodima/fix-has_many_through-dumpingRyuta Kamizono2018-02-091-0/+5
|\ | | | | | | Fix marshaling of models with `has_many :through` associations
| * Fix marshaling of models with `has_many :through` associationsfatkodima2018-02-081-0/+6
|/
* Remove extra whitespaceDaniel Colson2018-01-254-25/+25
|
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-259-68/+68
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-2513-242/+242
|
* Use respond_to test helpersDaniel Colson2018-01-251-1/+1
|
* Fix building has_one through recordRyuta Kamizono2018-01-231-0/+12
| | | | Fixes #31762.
* Don't update counter cache when through record was not destroyedEugene Kenny2018-01-141-0/+10
| | | | | | When removing a record from a has many through association, the counter cache was being updated even if the through record halted the callback chain and prevented itself from being destroyed.
* Merge pull request #23146 from piotrj/issue_18424Ryuta Kamizono2018-01-111-0/+19
|\ | | | | | | When deleting through records, take into account association conditions
| * When deleting through records, take into account association conditionsPiotr Jakubowski2016-05-041-0/+16
| | | | | | | | | | | | | | | | Fixes #18424. When deleting through records, it didn't take into account the conditions that may have been affecting join model table, but was defined in association definition.
* | Fix `stale_state` for nested `has_many :through` associationsRyuta Kamizono2018-01-101-12/+28
| | | | | | | | Need reloading when through record has replaced.
* | Merge pull request #16314 from ↵Ryuta Kamizono2018-01-101-0/+29
|\ \ | | | | | | | | | | | | | | | zoltankiss/allow-nested-has-many-associations-on-unpersisted-parent-instances fix nested `has many :through` associations on unpersisted parent instances
| * | Fix nested `has many :through` associations on unpersisted instancesZoltan Kiss2015-03-261-0/+29
| | | | | | | | | | | | Fixes: #16313
* | | Fix newly added reflection order when redefining associationRyuta Kamizono2018-01-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently reflections keeps the order when first added even if when redefining association. As a result of the order, redefining through association which use newly added association will raise `HasManyThroughOrderError`. We need to redefine reflection order as well when redefining association. Fixes #31068.
* | | Merge pull request #27561 from fishbrain/count-all-in-has-many-associationRyuta Kamizono2018-01-031-0/+8
|\ \ \ | | | | | | | | | | | | Use `count(:all)` in HasManyAssociation#count_records
| * | | Use `count(:all)` in HasManyAssociation#count_recordsKlas Eskilson2017-02-071-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Calling `count` on an association can cause invalid SQL queries to be created where the `SELECT COUNT(a, b, c)` function receives multiple columns. This will cause a `StatementInvalid` exception later on. Solution: Use `count(:all)`, which generates a `SELECT COUNT(*)...` query independently of the association. This also includes a test case that, before the fix, broke.
* | | | Add test case for `collection_singular_ids` with symbol primary keysRyuta Kamizono2018-01-011-0/+8
| | | | | | | | | | | | | | | | This is a regression test for #27864.
* | | | Bugfix foreign key replacement in inverse associationBogdan Gusiev2017-12-271-0/+9
| | | | | | | | | | | | | | | | when model is added to collection association
* | | | Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the futureRyuta Kamizono2017-12-143-7/+7
| | | | | | | | | | | | | | | | Follow up of #31432.
* | | | Enable `Layout/SpaceBeforeComma` rubocop rule, and fixed moreRyuta Kamizono2017-12-122-2/+2
| | | | | | | | | | | | | | | | Follow up of #31390.
* | | | Merge pull request #31214 from ↵Eileen M. Uchitelle2017-11-291-0/+10
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | chopraanmol1/bug_fix_has_one_inverse_owner_reload_from_validation Inverse instance should not be reloaded during autosave if called in validation
| * | | | Inverse instance should not be reloaded during autosave if called in validationAnmol Chopra2017-11-271-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | Record saved in save_has_one_association already make call to association.loaded! via record's before_save callback of save_belongs_to_association, but this will reload object if accessed in record's validation.
* | | | | Provide arguments to RecordNotFoundNikita Misharin2017-11-251-1/+4
|/ / / /
* | | | Merge pull request #27947 from mastahyeti/unsafe_raw_sqlMatthew Draper2017-11-141-5/+5
|\ \ \ \ | | | | | | | | | | | | | | | Disallow raw SQL in dangerous AR methods
| * | | | try using regexesBen Toews2017-11-099-28/+28
| | | | |
| * | | | allow table name and direction in string order argBen Toews2017-11-096-86/+86
| | | | |
| * | | | work around deprecation warnings in a bunch of testsBen Toews2017-11-0910-115/+115
| | | | |
* | | | | Set counter caches to correct values in fixturesBogdan Gusiev2017-11-082-2/+2
|/ / / /
* | | | Fix preloading polymorphic multi-level through associationRyuta Kamizono2017-11-061-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is partially fixed by e617fb57 when through association has already loaded. Otherwise, second level through association should respect `preload_scope`. Fixes #30242. Closes #30076. [Ryuta Kamizono & CicholGricenchos]
* | | | Fix preloading polymorphic association when through association has already ↵Ryuta Kamizono2017-11-061-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | loaded If through association has already loaded, `source_type` is ignored to loaded through records. The loaded records should be filtered by `source_type` in that case. Fixes #30904.
* | | | `source_type_scope` should respect correct table aliasRyuta Kamizono2017-10-301-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `join_scopes` in `PolymorphicReflection` is passed aliased `table`, so it should be respected for `source_type_scope`. Closes #13969. Fixes #13920. Fixes #15190.
* | | | Fix all `s/trough/through/`Ryuta Kamizono2017-10-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` % git grep -n trough activerecord/test/cases/associations/has_many_through_associations_test.rb:1253: def test_has_many_trough_with_scope_that_has_joined_same_table_with_parent_relation ```
* | | | Fix typo `s/trough/through/`Ryuta Kamizono2017-10-271-1/+1
| | | |
* | | | Merge pull request #30682 from ahorek/fix_scope_forRyuta Kamizono2017-10-271-0/+5
|\ \ \ \ | | | | | | | | | | delegate scope_for on PolymorphicReflection
| * | | | delegate scope forpavel2017-10-271-0/+5
| | | | |
* | | | | fix initial countpavel2017-10-271-0/+4
|/ / / /
* | | | Ensure associations doesn't table name collide with aliased joinsRyuta Kamizono2017-10-241-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | Currently alias tracker only refer a table name, doesn't respect an alias name. Should use `join.left.name` rather than `join.left.table_name`.
* | | | Remove deprecated support to passing a class to `:class_name` on associationsRafael Mendonça França2017-10-231-13/+0
| | | |
* | | | Fix duplicate aliases when using both INNER/LEFT JOINsRyuta Kamizono2017-10-231-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It should be shared the count of alias tracking in both INNER/LEFT JOINs to avoid duplicate aliases. Fixes #30504. Closes #30410.