1. 09 11月, 2012 5 次提交
    • J
      fix warnings · 1489303d
      Jon Leighton 提交于
      1489303d
    • J
      Delegate all calculations to the scope. · edd94cee
      Jon Leighton 提交于
      So that the scope may be a NullRelation and return a result without
      executing a query.
      
      Fixes #7928
      edd94cee
    • J
      CollectionProxy#pluck issues no query for a new_record? owner · 11b846ee
      Jon Leighton 提交于
      Fixes #8102.
      
      I couldn't find a nicer way to deal with this than delegate the call to
       #scope, which will be a NullRelation when we want it to be.
      11b846ee
    • J
      Nullify the relation at a more general level. · aae4f357
      Jon Leighton 提交于
      This allows us to avoid hacks like the "return 0 if owner.new_record?"
      in #count (which this commit removes).
      
      Also, the relevant foreign key may actually be present even on a new
      owner record, in which case we *don't* want a null relation. This logic
      is encapsulated in the #null_scope? method.
      
      We also need to make sure that the CollectionProxy is not 'infected'
      with the NullRelation module, or else the methods from there will
      override the definitions in CollectionProxy, leading to incorrect
      results. Hence the nullify: false option to CollectionAssociation#scope.
      (This feels a bit nasty but I can't think of a better way.)
      aae4f357
    • J
      Relations built off collection associations with an unsaved owner should be null relations · 0130c174
      Jon Leighton 提交于
      For example, the following should not run any query on the database:
      
      Post.new.comments.where(body: 'omg').to_a # => []
      
      Fixes #5215.
      0130c174
  2. 22 9月, 2012 2 次提交
  3. 17 9月, 2012 2 次提交
  4. 13 9月, 2012 1 次提交
  5. 02 8月, 2012 3 次提交
    • J
      s/scoped/scope/ · b33e7ba1
      Jon Leighton 提交于
      b33e7ba1
    • J
      Add CollectionProxy#scope · 0e1cafcb
      Jon Leighton 提交于
      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
      0e1cafcb
    • J
      Use explicit delegations · 26d3e325
      Jon Leighton 提交于
      This makes it easier to see what the documentation refers to.
      
      It also means that we are not doing unnecessary work for delegations
      that have no args / splats / block / etc.
      26d3e325
  6. 31 7月, 2012 2 次提交
  7. 28 7月, 2012 1 次提交
  8. 29 5月, 2012 1 次提交
    • F
      Add support for CollectionAssociation#delete by Fixnum or String · 39f06984
      Francesco Rodriguez 提交于
      I found the next issue between CollectionAssociation `delete`
      and `destroy`.
      
          class Person < ActiveRecord::Base
            has_many :pets
          end
      
          person.pets.destroy(1)
          # => OK, returns the destroyed object
      
          person.pets.destroy("2")
          # => OK, returns the destroyed object
      
          person.pets.delete(1)
          # => ActiveRecord::AssociationTypeMismatch
      
          person.pets.delete("2")
          # => ActiveRecord::AssociationTypeMismatch
      
      Adding support for deleting with a fixnum or string like
      `destroy` method.
      39f06984
  9. 28 5月, 2012 1 次提交
  10. 27 5月, 2012 1 次提交
  11. 26 5月, 2012 5 次提交
  12. 24 5月, 2012 1 次提交
  13. 23 5月, 2012 8 次提交
  14. 22 5月, 2012 7 次提交