aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
...
* | 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.
* | | | Ensure associations doesn't table name collide with string joinsRyuta Kamizono2017-10-231-0/+5
| | | | | | | | | | | | | | | | | | | | Currently we have no test for alias tracking with string joins. I've add test case for that to catch a future regression.
* | | | Add a test case that eager-loading with a polymorphic association and using ↵Ryuta Kamizono2017-10-161-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `exists?` This test covers the case of 02da8aea. Previously `exists?` was always eager-loading the includes values. But now it is eager-loaded only when necessary since 07a611e0. So the case of the eager-loading had not covered in the test.
* | | | Show the failed queries in `test_has_one_does_not_use_order_by`Ryuta Kamizono2017-10-141-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | For investigating the cause of failure. https://travis-ci.org/rails/rails/jobs/287474883#L797-L799
* | | | Joined tables in association scope doesn't use the same aliases with the ↵Ryuta Kamizono2017-10-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | parent relation's aliases Building association scope in join dependency should respect the parent relation's aliases to avoid using the same alias name more than once. Fixes #30681.
* | | | `has_many :through` with unscope should affect to through scopeRyuta Kamizono2017-09-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The order of scope evaluation should be from through scope to the association's own scope. Otherwise the association's scope cannot affect to through scope. Fixes #13677. Closes #28449.
* | | | Don't expose `find_all_ordered` utility method in testsRyuta Kamizono2017-09-021-4/+5
| | | | | | | | | | | | | | | | Because this is not a test case.
* | | | Fix preloading through association with custom scopeRyuta Kamizono2017-09-021-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If `reflection_scope.where_clause` is not empty, `through_scope` should be joined the source association. But if `values[:references]` in `reflection_scope` is empty, the source association will not be joined. It should use `source_reflection.table_name` in that case. Fixes #22535. Closes #28763.
* | | | Add a test case for preloading through association with implicit sourceRyuta Kamizono2017-09-021-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If `reflection_scope.where_clause` is not empty, `through_scope` should be joined the source association. But if the through association doesn't have explicit `:source`, `options[:source]` will be nil and `scope.includes_values` will also be empty. It should use `source_reflection.name` rather than `options[:source]`. Fixed by a26cff3c1235c61cd0135bed4ef63d7be452b458. Fixes #11078. Fixes #26129. Closes #14312. Closes #29155. Closes #29841.
* | | | :warning: assigned but unused variable - messageAkira Matsuda2017-09-011-6/+6
| | | |
* | | | Should work inverse association when eager loadingRyuta Kamizono2017-08-251-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This regression was caused by caa178c1. The block for `set_inverse_instance` should also be passed to join dependency. Fixes #30402.
* | | | Load both `:authors` and `:author_addresses` to keep data integrityYasuo Honda2017-08-222-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `:authors` has a foreign key to `:author_addresses`. If only `:authors` fixture loaded into the database which supports foreign key and checks the existing data when enabling foreien keys like Oracle, it raises the following error `ORA-02298: cannot validate (ARUNIT.FK_RAILS_94423A17A3) - parent keys not found` It is because there is no parent data exists in `author_addresses` table. Here are how other database with foreign key support works: - MySQL does not check the existing data when enabling foreign key by `foreign_key_checks=1` https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_foreign_key_checks > Setting foreign_key_checks to 1 does not trigger a scan of the existing table data. Therefore, rows added to the table while foreign_key_checks=0 will not be verified for consistency. - PostgreSQL database itself has a feature to check existing data when enabling foreign key and discussed at #27636, which is reverted.
* | | | Automatically guess the inverse associations for STIyui-knk2017-08-221-1/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ActiveRecord associations automatically guess the inverse associations. But this feature does not work correctly on assoctions for STI. For example, before this commit ``` class Post < ActiveRecord::Base belongs_to :author end class SpecialPost < Post; end class Author < ActiveRecord::Base has_many :posts has_many :special_posts end ``` `author.posts.first.author` works correctly, but `author.special_posts.first.author` does not work correctly.
* | | | Add deterministic sorting order for `test_taking_with_a_number`Ryuta Kamizono2017-08-181-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | Otherwise random CI failure will be caused. https://travis-ci.org/rails/rails/jobs/265848046#L777
* | | | Through scope should not be affected by scopingRyuta Kamizono2017-08-151-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | Follow up of #29834. Fixes #30266.
* | | | Merge pull request #30169 from awortham/awortham/awortham/fix-sql-distinct-bugRafael Mendonça França2017-08-141-0/+26
|\ \ \ \ | | | | | | | | | | | | | | | Ensure sum honors distinct on has_many through
| * | | | Ensure sum honors distinct on has_many throughAaron Wortham2017-08-141-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using a has_many through relation and then summing an attribute the distinct was not being used. This will ensure that when summing an attribute, the number is only used once when distinct has been used.
* | | | | Merge pull request #30215 from untidy-hair/clarify-abstract-or-not-in-testsRafael França2017-08-141-3/+3
|\ \ \ \ \ | | | | | | | | | | | | Clarify base_class tests on abstract STI vs concrete STI
| * | | | | Clarify base_class tests on abstract STI vs concrete STIYukio Mizuta2017-08-121-3/+3
| |/ / / /
* / / / / Fix `reflection.association_primary_key` for `has_many` associationsRyuta Kamizono2017-08-132-17/+14
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is incorrect to treat `options[:primary_key]` as `association_primary_key` if `has_many` associations because the `:primary_key` means the column on the owner record, not on the association record. It will break `ids_reader` and `ids_writer`. ```ruby people(:david).essay_ids # => ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'essays.first_name' in 'field list': SELECT `essays`.first_name FROM `essays` WHERE `essays`.`writer_id` = 'David' ``` Fixes #14439.
* | | | Merge pull request #30103 from yahonda/has_one_associations_failuresRafael França2017-08-111-1/+1
|\ \ \ \ | | | | | | | | | | Add `:authors` to address random failures at HasOneAssociationsTest
| * | | | Add `:authors` fixture to address two random failures at HasOneAssociationsTestYasuo Honda2017-08-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * sqlite3 - 2 failures ```ruby $ ARCONN=sqlite3 bin/test test/cases/associations/has_one_associations_test.rb test/cases/view_test.rb --seed 48032 -n "/^(?:ViewWithoutPrimaryKeyTest#(?:test_attributes)|HasOneAssociationsTest#(?:test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy|test_destroyed_by_association_set_in_child_destroy_callback_on_replace))$/" --verbose Using sqlite3 Run options: --seed 48032 -n "/^(?:ViewWithoutPrimaryKeyTest#(?:test_attributes)|HasOneAssociationsTest#(?:test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy|test_destroyed_by_association_set_in_child_destroy_callback_on_replace))$/" --verbose ViewWithoutPrimaryKeyTest#test_attributes = 0.02 s = . HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_replace = 0.12 s = F HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy = 0.01 s = F Finished in 0.162504s, 18.4610 runs/s, 18.4610 assertions/s. 1) Failure: HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_replace [/home/yahonda/git/rails/activerecord/test/cases/associations/has_one_associations_test.rb:725]: Expected true to be nil or false 2) Failure: HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy [/home/yahonda/git/rails/activerecord/test/cases/associations/has_one_associations_test.rb:715]: Expected true to be nil or false 3 runs, 3 assertions, 2 failures, 0 errors, 0 skips ``` * mysql2 - 1 failure ``` $ ARCONN=mysql2 bin/test test/cases/associations/has_one_associations_test.rb test/cases/view_test.rb --seed 48032 -n "/^(?:ViewWithoutPrimaryKeyTest#(?:test_attributes)|HasOneAssociationsTest#(?:test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy|test_destroyed_by_association_set_in_child_destroy_callback_on_replace))$/" --verbose Using mysql2 Run options: --seed 48032 -n "/^(?:ViewWithoutPrimaryKeyTest#(?:test_attributes)|HasOneAssociationsTest#(?:test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy|test_destroyed_by_association_set_in_child_destroy_callback_on_replace))$/" --verbose ViewWithoutPrimaryKeyTest#test_attributes = 0.07 s = . HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_replace = 0.27 s = F HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy = 0.02 s = . Finished in 0.362779s, 8.2695 runs/s, 8.2695 assertions/s. 1) Failure: HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_replace [/home/yahonda/git/rails/activerecord/test/cases/associations/has_one_associations_test.rb:725]: Expected true to be nil or false 3 runs, 3 assertions, 1 failures, 0 errors, 0 skips ``` * postgresql - 0 failures ```ruby $ ARCONN=postgresql bin/test test/cases/associations/has_one_associations_test.rb test/cases/view_test.rb --seed 48032 -n "/^(?:ViewWithoutPrimaryKeyTest#(?:test_attributes)|HasOneAssociationsTest#(?:test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy|test_destroyed_by_association_set_in_child_destroy_callback_on_replace))$/" --verbose Using postgresql Run options: --seed 48032 -n "/^(?:ViewWithoutPrimaryKeyTest#(?:test_attributes)|HasOneAssociationsTest#(?:test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy|test_destroyed_by_association_set_in_child_destroy_callback_on_replace))$/" --verbose ViewWithoutPrimaryKeyTest#test_attributes = 0.06 s = . HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_parent_destroy = 0.22 s = . HasOneAssociationsTest#test_destroyed_by_association_set_in_child_destroy_callback_on_replace = 0.02 s = . Finished in 0.311217s, 9.6396 runs/s, 9.6396 assertions/s. 3 runs, 3 assertions, 0 failures, 0 errors, 0 skips ```