Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Commits on Feb 25, 2014
  1. Jon Leighton

    Merge remote-tracking branch 'chancancode/fix_instance_method_already…

    jonleighton authored
    …_implemented'
    
    Conflicts:
    	activerecord/CHANGELOG.md
Commits on Jan 4, 2014
  1. Jon Leighton

    Fix mergefail in changelog

    jonleighton authored
    The line was duplicated
Commits on Jan 2, 2014
  1. Jon Leighton

    Automatically maintain test database schema

    jonleighton authored
    * Move check from generated helper to test_help.rb, so that all
      applications can benefit
    * Rather than just raising when the test schema has pending migrations,
      try to load in the schema and only raise if there are pending
      migrations afterwards
    * Opt out of the check by setting
      config.active_record.maintain_test_schema = false
    * Deprecate db:test:* tasks. The test helper is now fully responsible
      for maintaining the test schema, so we don't need rake tasks for this.
      This is also a speed improvement since we're no longer reloading the
      test database on every call to "rake test".
Commits on Nov 20, 2013
  1. Jon Leighton

    Fix ActiveRecord::Relation#unscope

    jonleighton authored
    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
    94924dc, 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.
Commits on Jun 28, 2013
  1. Jon Leighton

    Apply default scope when joining associations.

    jonleighton authored
    For example:
    
        class Post < ActiveRecord::Base
          default_scope -> { where published: true }
        end
    
        class Comment
          belongs_to :post
        end
    
    When calling `Comment.join(:post)`, we expect to receive only
    comments on published posts, since that is the default scope for
    posts.
    
    Before this change, the default scope from `Post` was not applied,
    so we'd get comments on unpublished posts.
Commits on Jun 19, 2013
  1. Jon Leighton

    Revert "Merge pull request #10566 from neerajdotname/10509d"

    jonleighton authored
    This reverts commit 2b817a5, reversing
    changes made to 353a398.
    
    Conflicts:
    	activerecord/CHANGELOG.md
    
    Reason: the build broke
Commits on May 3, 2013
  1. Jon Leighton

    Merge pull request #10417 from jholton/fix_association_auto_save

    jonleighton authored
    autosave_association issue that occurs when table has unique index (resubmission)
Commits on Apr 19, 2013
  1. Jon Leighton

    Revert "Merge pull request #10183 from jholton/fix_association_auto_s…

    jonleighton authored
    …ave"
    
    This reverts commit e8727d3, reversing
    changes made to d098e1c.
    
    Reason: it broke the mysql build
Commits on Apr 5, 2013
  1. Jon Leighton

    Merge pull request #9996 from mikz/master

    jonleighton authored
    Association with inverse_of does not set the parent in association building block
Commits on Mar 8, 2013
  1. Jon Leighton
Commits on Jan 27, 2013
  1. Jon Leighton

    Prevent Relation#merge from collapsing wheres on the RHS

    jonleighton authored
    This caused a bug with the new associations implementation, because now
    association conditions are represented as Arel nodes internally right up
    to when the whole thing gets turned to SQL.
    
    In Rails 3.2, association conditions get turned to raw SQL early on,
    which prevents Relation#merge from interfering.
    
    The current implementation was buggy when a default_scope existed on the
    target model, since we would basically end up doing:
    
      default_scope.merge(association_scope)
    
    If default_scope contained a where(foo: 'a') and association_scope
    contained a where(foo: 'b').where(foo: 'c') then the merger would see
    that the same column is representated on both sides of the merge and
    collapse the wheres to all but the last: where(foo: 'c')
    
    Now, the RHS of the merge is left alone.
    
    Fixes #8990
Commits on Jan 18, 2013
  1. Jon Leighton

    Undeprecate the :extend option

    jonleighton authored
    Suggested by @dhh.
    
    It doesn't affect the generated SQL, so seems reasonable to continue to
    allow it as an association option.
Commits on Oct 26, 2012
  1. Jon Leighton

    Remove ActiveRecord::Model

    jonleighton authored
    In the end I think the pain of implementing this seamlessly was not
    worth the gain provided.
    
    The intention was that it would allow plain ruby objects that might not
    live in your main application to be subclassed and have persistence
    mixed in. But I've decided that the benefit of doing that is not worth
    the amount of complexity that the implementation introduced.
Commits on Oct 19, 2012
  1. Jon Leighton

    Get rid of the ActiveRecord::Model::DeprecationProxy thing.

    jonleighton authored
    I think it's going to be too much pain to try to transition the
    :active_record load hook from executing against Base to executing
    against Model.
    
    For example, after Model is included in Base, and modules included in
    Model will no longer get added to the ancestors of Base.
    
    So plugins which wish to be compatible with both Model and Base should
    use the :active_record_model load hook which executes *before* Base gets
    loaded.
    
    In general, ActiveRecord::Model is an advanced feature at the moment and
    probably most people will continue to inherit from ActiveRecord::Base
    for the time being.
  2. Jon Leighton

    Rename the partial_updates config to partial_writes

    jonleighton authored
    This reflects the fact that it now impact inserts as well as updates.
  3. Jon Leighton
  4. Jon Leighton

    Add Relation#find_or_create_by and friends

    jonleighton authored
    This is similar to #first_or_create, but slightly different and a nicer
    API. See the CHANGELOG/docs in the commit.
    
    Fixes #7853
Commits on Sep 28, 2012
  1. Jon Leighton

    Support for partial inserts.

    jonleighton authored
    When inserting new records, only the fields which have been changed
    from the defaults will actually be included in the INSERT statement.
    The other fields will be populated by the database.
    
    This is more efficient, and also means that it will be safe to
    remove database columns without getting subsequent errors in running
    app processes (so long as the code in those processes doesn't
    contain any references to the removed column).
Commits on Sep 21, 2012
  1. Jon Leighton

    Support for specifying transaction isolation level

    jonleighton authored
    If your database supports setting the isolation level for a transaction,
    you can set it like so:
    
      Post.transaction(isolation: :serializable) do
        # ...
      end
    
    Valid isolation levels are:
    
    * `:read_uncommitted`
    * `:read_committed`
    * `:repeatable_read`
    * `:serializable`
    
    You should consult the documentation for your database to understand the
    semantics of these different levels:
    
    * http://www.postgresql.org/docs/9.1/static/transaction-iso.html
    * https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
    
    An `ActiveRecord::TransactionIsolationError` will be raised if:
    
    * The adapter does not support setting the isolation level
    * You are joining an existing open transaction
    * You are creating a nested (savepoint) transaction
    
    The mysql, mysql2 and postgresql adapters support setting the
    transaction isolation level. However, support is disabled for mysql
    versions below 5, because they are affected by a bug
    (http://bugs.mysql.com/bug.php?id=39170) which means the isolation level
    gets persisted outside the transaction.
Commits on Aug 17, 2012
  1. Jon Leighton

    Renaming active_record_deprecated_finders to activerecord-deprecated_…

    jonleighton authored
    …finders
    
    For consistency with the other AR extension plugins we are creating.
Commits on Aug 10, 2012
  1. Jon Leighton

    Remove the dependent_restrict_raises option.

    jonleighton authored
    It's not really a good idea to have this as a global config option. We
    should allow people to specify the behaviour per association.
    
    There will now be two new values:
    
    * :dependent => :restrict_with_exception implements the current
      behaviour of :restrict. :restrict itself is deprecated in favour of
      :restrict_with_exception.
    * :dependent => :restrict_with_error implements the new behaviour - it
      adds an error to the owner if there are dependent records present
    
    See #4727 for the original discussion of this.
Commits on Aug 3, 2012
  1. Jon Leighton

    Remove ActiveRecord::Base.to_a

    jonleighton authored
    On reflection, it seems like a bit of a weird method to have on
    ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
  2. Jon Leighton
  3. Jon Leighton

    Allow Relation#merge to take a proc.

    jonleighton authored
    This was requested by DHH to allow creating of one's own custom
    association macros.
    
    For example:
    
        module Commentable
          def has_many_comments(extra)
            has_many :comments, -> { where(:foo).merge(extra) }
          end
        end
    
        class Post < ActiveRecord::Base
          extend Commentable
          has_many_comments -> { where(:bar) }
        end
Commits on Aug 1, 2012
  1. Jon Leighton

    Add CollectionProxy#scope

    jonleighton authored
    This can be used to get a Relation from an association.
    
    Previously we had a #scoped method, but we're deprecating that for
    AR::Base, so it doesn't make sense to have it here.
    
    This was requested by DHH, to facilitate code like this:
    
        Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
          @topics      = @project.topics.scope
          @todolists   = @project.todolists.scope
          @attachments = @project.attachments.scope
          @documents   = @project.documents.scope
        end
  2. Jon Leighton

    Add `Relation#load`

    jonleighton authored
    This method explicitly loads the records and then returns `self`.
    
    Rather than deciding between "do I want an array or a relation?",
    most people are actually asking themselves "do I want to eager load
    or lazy load?" Therefore, this method provides a way to explicitly
    eager-load without having to switch from a `Relation` to an array.
    
    Example:
    
        @posts = Post.where(published: true).load
  3. Jon Leighton
  4. Jon Leighton

    Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."

    jonleighton authored
    This reverts commit 3803fcc.
    
    Conflicts:
    	activerecord/CHANGELOG.md
    
    It will be deprecated only in 4.0, and removed properly in 4.1.
Commits on Jul 27, 2012
  1. Jon Leighton
Commits on Jul 20, 2012
  1. Jon Leighton
Commits on Jul 7, 2012
  1. Jon Leighton

    fixup changelog

    jonleighton authored
Commits on Jul 6, 2012
  1. Jon Leighton

    Show the records in Relation#inspect

    jonleighton authored
    The reason for removing the previous implementation of `#inspect` was
    that it hid from you that you were dealing with a `Relation` rather than
    an `Array`.
    
    But it is still useful to be able to see the records, particularly if you're
    writing something like the following in tests:
    
        assert_equal [foo], Post.where(:bar)
    
    If the assertion fails, you want to see what records were actually
    loaded.
    
    So this implementation makes it clear that you've got a `Relation`, but
    also shows your records.
Commits on May 18, 2012
  1. Jon Leighton

    fix typo [ci skip]

    jonleighton authored
  2. Jon Leighton
Commits on Apr 12, 2012
  1. Jon Leighton

    Add bang versions of relation query methods.

    jonleighton authored
    The main reason for this is that I want to separate the code that does
    the mutating from the code that does the cloning.
Something went wrong with that request. Please try again.