1. 31 1月, 2014 1 次提交
  2. 28 1月, 2014 1 次提交
  3. 22 1月, 2014 1 次提交
    • J
      Ensure AR #second, #third, etc. finders work through associations · 03855e79
      Jason Meller 提交于
      This commit fixes two regressions introduced in cafe31a0 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.
      03855e79
  4. 19 12月, 2013 1 次提交
  5. 26 11月, 2013 3 次提交
    • H
      changed update counter to act on unscoped model · 45d4d141
      heruku 提交于
      45d4d141
    • B
      Raise `RecordNotDestroyed` when children can't be replaced · 5aab0c05
      Brian Thomas Storti 提交于
      Fixes #12812
      Raise `ActiveRecord::RecordNotDestroyed` when a child marked with
      `dependent: destroy` can't be destroyed.
      
      The following code:
      ```ruby
      class Post < ActiveRecord::Base
        has_many :comments, dependent: :destroy
      end
      
      class Comment < ActiveRecord::Base
        before_destroy do
          return false
        end
      end
      
      post = Post.create!(comments: [Comment.create!])
      post.comments = [Comment.create!]
      ````
      
      would result in a `post` with two `comments`.
      With this commit, the same code would raise a `RecordNotDestroyed`
      exception, keeping the `post` with the same `comment`.
      5aab0c05
    • V
      Fix some minor typos [ci skip] · 82de1eda
      Vipul A M 提交于
      82de1eda
  6. 21 11月, 2013 1 次提交
    • J
      Fix ActiveRecord::Relation#unscope · 64b9e93b
      Jon Leighton 提交于
      I'm pretty confused about the addition of this method. The documentation
      says that it was intended to allow the removal of values from the
      default scope (in contrast to #except). However it behaves exactly the
      same as except: https://gist.github.com/jonleighton/7537008 (other than
      having a slightly enhanced syntax).
      
      The removal of the default scope is allowed by
      94924dc3, which was not a change we
      could make until 4.1 due to the need to deprecate things. However after
      that change #unscope still gives us nothing that #except doesn't already
      give us.
      
      However there *is* a desire to be able to unscope stuff in a way that
      persists across merges, which would allow associations to be defined
      which unscope stuff from the default scope of the associated model. E.g.
      
        has_many :comments, -> { unscope where: :trashed }
      
      So that's what this change implements. I've also corrected the
      documentation. I removed the guide references to #except as I think
      unscope really supercedes #except now.
      
      While we're here, there's also a potential desire to be able to write
      this:
      
        has_many :comments, -> { unscoped }
      
      However, it doesn't make sense and would not be straightforward to
      implement. While with #unscope we're specifying exactly what we want to
      be removed from the relation, with "unscoped" we're just saying that we
      want it to not have some things which were added earlier on by the
      default scope. However in the case of an association, we surely don't
      want *all* conditions to be removed, otherwise the above would just
      become "SELECT * FROM comments" with no foreign key constraint.
      
      To make the above work, we'd have to somehow tag the relation values
      which get added when evaluating the default scope in order to
      differentiate them from other relation values. Which is way too much
      complexity and therefore not worth it when most use cases can be
      satisfied with unscope.
      
      Closes #10643, #11061.
      64b9e93b
  7. 17 11月, 2013 1 次提交
  8. 02 11月, 2013 2 次提交
  9. 29 10月, 2013 1 次提交
  10. 28 9月, 2013 1 次提交
    • P
      Removed where_values_hash from AR::NullRelation · 8fb0de2c
      Paul Nikitochkin 提交于
      In order to build associated records for owners which has not been saved
      need to get where values to use as default attributes.
      But for new record owner uses `ActiveRecord::NullRelation` which
      override `where_values_hash` to return empty hash stub.
      
      `where_values_hash` is not used to invoke any sql query, but good to
      build others chains (even will be never executed) like:
      
      ```ruby
        post          = Post.new
        admin_comment = post.admin_comments.build
      
        assert_equal 'Admin', admin_comment.author
      ```
      
      Closes #11376, #11676, #11675
      8fb0de2c
  11. 26 9月, 2013 2 次提交
  12. 10 9月, 2013 1 次提交
    • L
      Make CollectionAssociation first/last with integer fetch with query · 8875e28a
      Lann Martin 提交于
      When first or last is called with an integer on an unloaded association,
      the entire collection is loaded. This differs surprisingly from the
      behavior of Relation#first/last, which translate the call into a limit
      query. For large collections this can make a big difference in
      performance.
      
      Change CollectionAssociation#fetch_first_or_last_using_find? to make
      this kind of call delegate to Relation.
      8875e28a
  13. 04 9月, 2013 1 次提交
  14. 30 7月, 2013 1 次提交
    • R
      Revert change on ActiveRecord::Relation#order method that prepends new · 92c5a224
      Rafael Mendonça França 提交于
      order on the old ones
      
      The previous behavior added a major backward incompatibility since it
      impossible to have a upgrade path without major changes on the
      application code.
      
      We are taking the most conservative path to be consistent with the idea
      of having a smoother upgrade on Rails 4.
      
      We are reverting the behavior for what was in Rails 3.x and,
      if needed, we will implement a new API to prepend the order clauses in
      Rails 4.1.
      92c5a224
  15. 03 7月, 2013 2 次提交
  16. 02 7月, 2013 2 次提交
  17. 30 6月, 2013 1 次提交
    • N
      Do not invoke callbacks when delete_all is called · f319e4a9
      Neeraj Singh 提交于
      Method `delete_all` should not be invoking callbacks and this
      feature was deprecated in Rails 4.0. This is being removed.
      `delete_all` will continue to honor the `:dependent` option. However
      if `:dependent` value is `:destroy` then the default deletion
      strategy for that collection will be applied.
      
      User can also force a deletion strategy by passing parameter to
      `delete_all`. For example you can do `@post.comments.delete_all(:nullify)`
      f319e4a9
  18. 24 6月, 2013 2 次提交
  19. 22 6月, 2013 1 次提交
  20. 18 6月, 2013 1 次提交
  21. 01 6月, 2013 1 次提交
  22. 23 5月, 2013 1 次提交
    • Y
      Fix the `:primary_key` option for `has_many` associations. · ef99c114
      Yves Senn 提交于
      When removing records from a `has_many` association it used
      the `primary_key` defined on the association.
      
      Our test suite didn't fail because on all occurences of `:primary_key`,
      the specified column was available in both tables. This prevented the
      code from raising an exception but it still behaved badly.
      
      I added a test-case to prevent regressions that failed with:
      
      ```
        1) Error:
      HasManyAssociationsTest#test_has_many_assignment_with_custom_primary_key:
      ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: essays.first_name: UPDATE "essays" SET "writer_id" = NULL WHERE "essays"."writer_id" = ? AND "essays"."first_name" IS NULL
      ```
      ef99c114
  23. 22 4月, 2013 1 次提交
    • M
      Update counter cache when pushing into association · 1e27f1c5
      Matthew Robertson 提交于
      This commit fixes a regression bug in which counter_cache columns
      were not being updated correctly when newly created records were
      being pushed into an assocation. EG:
      
          # this was fine
          @post.comment.create!
      
          # this was fine
          @comment = Comment.first
          @post.comments << @comment
      
          # this would not update counters
          @post.comments << Comment.create!
      1e27f1c5
  24. 08 4月, 2013 1 次提交
  25. 16 3月, 2013 1 次提交
  26. 25 2月, 2013 1 次提交
  27. 24 2月, 2013 1 次提交
  28. 27 1月, 2013 1 次提交
    • D
      Fix cases where delete_records on a has_many association caused errors · 0a71c7b8
      Derek Kraan 提交于
      because of an ambiguous column name. This happened if the association
      model had a default scope that referenced a third table, and the third
      table also referenced the original table (with an identical
      foreign_key).
      
      Mysql requires that ambiguous columns are deambiguated by using the full
      table.column syntax. Postgresql and Sqlite use a different syntax for
      updates altogether (and don't tolerate table.name syntax), so the fix
      requires always including the full table.column and discarding it later
      for Sqlite and Postgresql.
      0a71c7b8
  29. 18 1月, 2013 4 次提交
  30. 13 1月, 2013 1 次提交