1. 27 11月, 2017 1 次提交
  2. 09 11月, 2017 2 次提交
  3. 23 8月, 2017 1 次提交
    • Y
      Load both `:authors` and `:author_addresses` to keep data integrity · 43c6a683
      Yasuo Honda 提交于
      `: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.
      43c6a683
  4. 22 8月, 2017 1 次提交
    • Y
      Automatically guess the inverse associations for STI · 30ef715d
      yui-knk 提交于
      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.
      30ef715d
  5. 20 7月, 2017 1 次提交
  6. 02 7月, 2017 2 次提交
  7. 01 7月, 2017 1 次提交
  8. 21 5月, 2017 1 次提交
  9. 20 4月, 2017 1 次提交
    • F
      Remove :polymorphic from INVALID_AUTOMATIC_INVERSE_OPTIONS · dc47c2be
      Fabian Schwahn 提交于
      This makes automatic inverse detection possible for polymorphic
      :has_one & :has_many possible.
      
      This resolves a number of issues, eg. `touch: true` on polymorphic relationships (#16446) and automatically setting inverse associations on newly built objects (#15028, #21843).
      dc47c2be
  10. 18 1月, 2017 1 次提交
  11. 31 8月, 2016 1 次提交
    • S
      Ensure that inverse associations are set before running callbacks · caa178c1
      Sean Griffin 提交于
      If a parent association was accessed in an `after_find` or
      `after_initialize` callback, it would always end up loading the
      association, and then immediately overwriting the association we just
      loaded. If this occurred in a way that the parent's `current_scope` was
      set to eager load the child, this would result in an infinite loop and
      eventually overflow the stack.
      
      For records that are created with `.new`, we have a mechanism to
      perform an action before the callbacks are run. I've introduced the same
      code path for records created with `instantiate`, and updated all code
      which sets inverse instances on newly loaded associations to use this
      block instead.
      
      Fixes #26320.
      caa178c1
  12. 16 8月, 2016 1 次提交
  13. 07 8月, 2016 3 次提交
  14. 23 2月, 2016 1 次提交
  15. 25 10月, 2015 1 次提交
  16. 27 9月, 2015 1 次提交
    • E
      Fix regression in inverse_of on through associations · ee824c88
      eileencodes 提交于
      `inverse_of` on through associations was accidently removed/caused to
      stop working in commit f8d2899d which was part of a refactoring on
      `ThroughReflection`.
      
      To fix we moved `inverse_of` and `check_validity_of_inverse!` to the
      `AbstractReflection` so it's available to the `ThroughReflection`
      without having to dup any methods. We then need to delegate `inverse_name`
      method in `ThroughReflection`. `inverse_name` can't be moved to
      `AbstractReflection` without moving methods that set the instance
      variable `@automatic_inverse_of`.
      
      This adds a test that ensures that `inverse_of` on a `ThroughReflection`
      returns the correct class name, and the correct record for the inverse
      relationship.
      
      Fixes #21692
      ee824c88
  17. 16 6月, 2014 1 次提交
  18. 11 6月, 2014 1 次提交
  19. 05 6月, 2014 1 次提交
    • L
      Fix inverse associations test · 5b66fba6
      Leandro Facchinetti 提交于
      `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`.
      5b66fba6
  20. 14 10月, 2013 1 次提交
  21. 05 10月, 2013 1 次提交
  22. 15 8月, 2013 1 次提交
  23. 13 8月, 2013 1 次提交
  24. 22 6月, 2013 2 次提交
    • N
      do not load all child records for inverse case · 82882d41
      Neeraj Singh 提交于
      currently `post.comments.find(Comment.first.id)` would load all
      comments for the given post to set the inverse association.
      
      This has a huge performance penalty. Because if post has 100k
      records and all these 100k records would be loaded in memory
      even though the comment id was supplied.
      
      Fix is to use in-memory records only if loaded? is true. Otherwise
      load the records using full sql.
      
      Fixes #10509
      82882d41
    • N
      fix bad test by making number that fits for integer · 6741a0a1
      Neeraj Singh 提交于
      PR https://github.com/rails/rails/pull/10566 had to be reverted
      because after applying the fix test
      "test_raise_record_not_found_error_when_invalid_ids_are_passed"
      started failing.
      
      In this test invalid_id is being assigned a really large number
      which was causing following failure when PR #10566 was applied.
      
      ```
      RangeError: bignum too big to convert into `long long'
      SELECT  `interests`.* FROM `interests`
      WHERE `interests`.`man_id` = ? AND `interests`.`id` = ?
      LIMIT 1  [["man_id", 970345987], ["id", 2394823094892348920348523452345]]
      ```
      
      This test is not failing in master because when test code
      `man.interests.find(invalid_id)` is executed then interests
      are fully loaded in memory and no database query is executed.
      
      After PR #10566 was merged then test code
      `man.interests.find(invalid_id)` started executing sql query
      and hence the error.
      
      In case someone is wondering why the second part of query is not
      failing, then that's because the actual query does not require
      any variable substituation where the number is large. In that
      case the sql generate is following.
      
      ```
      SELECT `interests`.* FROM `interests`
      WHERE `interests`.`man_id` = ? AND `interests`.`id`
      IN (8432342, 2390102913, 2453245234523452)  [["man_id", 970345987]]
      ```
      6741a0a1
  25. 19 6月, 2013 2 次提交
    • J
      Revert "Merge pull request #10566 from neerajdotname/10509d" · e47b6dee
      Jon Leighton 提交于
      This reverts commit 2b817a5e, reversing
      changes made to 353a398b.
      
      Conflicts:
      	activerecord/CHANGELOG.md
      
      Reason: the build broke
      e47b6dee
    • N
      do not load all child records for inverse case · 2b73f780
      Neeraj Singh 提交于
      currently `post.comments.find(Comment.first.id)` would load all
      comments for the given post to set the inverse association.
      
      This has a huge performance penalty. Because if post has 100k
      records and all these 100k records would be loaded in memory
      even though the comment id was supplied.
      
      Fix is to use in-memory records only if loaded? is true. Otherwise
      load the records using full sql.
      
      Fixes #10509
      2b73f780
  26. 08 5月, 2013 1 次提交
  27. 02 4月, 2013 2 次提交
  28. 01 4月, 2013 1 次提交
    • M
      fix inverse_of association in block of new child · 44838159
      Michal Cichra 提交于
      This fixes inconsistency when building children of association
      which has inverse_of set properly.
      
      When creating new association object with a block:
      
          parent.association.build do |child|
            child.parent.equal?(parent) # false
          end
      
      So the block the `child.parent` did not point to the same object.
      But when the object is created it points to same instance:
      
          child = parent.association.build
          child.parent.equal?(parent) # true
      44838159
  29. 20 3月, 2013 1 次提交
  30. 02 11月, 2012 1 次提交
    • C
      Fix issue with collection associations and first(n)/last(n) · 694334c3
      Carlos Antonio da Silva 提交于
      When calling first(n) or last(n) in a collection, Active Record was
      improperly trying to set the inverse of instance in case that option
      existed. This change was introduced by
      fdf4eae5.
      
      In such cases we don't need to do that "manually", since the way
      collection will be loaded will already handle that, so we just skip
      setting the inverse association when any argument is given to
      first(n)/last(n).
      
      The test included ensures that these scenarios will have the inverse of
      instance set properly.
      
      Fixes #8087, Closes #8094.
      
      Squashed cherry-pick from d37d40b2 and c368b660.
      
      Conflicts:
      	activerecord/CHANGELOG.md
      	activerecord/lib/active_record/associations/collection_association.rb
      694334c3
  31. 18 8月, 2012 1 次提交
  32. 28 7月, 2012 1 次提交
  33. 27 4月, 2012 1 次提交