1. 04 1月, 2014 1 次提交
    • G
      Building new records with enum scopes now works as expected · 788bb40e
      Godfrey Chan 提交于
      Previously, this would give an `ArgumentError`:
      
         class Issue < ActiveRecord::Base
           enum :status, [:open, :finished]
         end
      
         Issue.open.build # => ArgumentError: '0' is not a valid status
         Issue.open.create # => ArgumentError: '0' is not a valid status
      
      PR #13542 muted the error, but the issue remains. This commit fixes
      the issue by allowing the enum value to be written directly via the
      setter:
      
         Issue.new.status = 0 # This now sets status to :open
      
      Assigning a value directly via the setter like this is not part of the
      documented public API, so users should not rely on this behavior.
      
      Closes #13530.
      788bb40e
  2. 02 1月, 2014 1 次提交
    • R
      Fix the enums writer methods · 7aebcb67
      Robin Dupret 提交于
      Previously, the writer methods would simply check whether the passed
      argument was the symbol representing the integer value of an enum field.
      Therefore, it was not possible to specify the numeric value itself but
      the dynamically defined scopes generate where clauses relying on this
      kind of values so a chained call to a method like `find_or_initialize_by`
      would trigger an `ArgumentError`.
      
      Reference #13530
      7aebcb67
  3. 11 12月, 2013 1 次提交
    • L
      Prevent invalid code when using dynamic finders with Ruby's reserved words. · 23ce3e5f
      Lauro Caetano 提交于
      The dynamic finder was creating the method signature with the parameters name,
      which may have reserved words and this way creating invalid Ruby code.
      
      Closes: #13261
      
          Example:
      
              # Before
              Dog.find_by_alias('dog name')
      
              # Was creating this method
              def self.find_by_alias(alias, options = {})
      
              # After
              Dog.find_by_alias('dog name')
      
              # Will create this method
              def self.find_by_alias(_alias, options = {})
      23ce3e5f
  4. 05 11月, 2013 1 次提交
  5. 04 11月, 2013 2 次提交
  6. 03 11月, 2013 2 次提交
  7. 14 10月, 2013 1 次提交
    • N
      scope_chain should not be mutated for other reflections · cd959295
      Neeraj Singh 提交于
      Currently `scope_chain` uses same array for building different
      `scope_chain` for different associations. During processing
      these arrays are sometimes mutated and because of in-place
      mutation the changed `scope_chain` impacts other reflections.
      
      Fix is to dup the value before adding to the `scope_chain`.
      
      Fixes #3882.
      cd959295
  8. 06 8月, 2013 2 次提交
  9. 18 5月, 2013 1 次提交
  10. 28 3月, 2013 1 次提交
  11. 21 3月, 2013 1 次提交
  12. 17 3月, 2013 1 次提交
    • M
      Refactor Person/Friendship relationships to be more intuitive · 1d6eabb6
      Mack Earnhardt 提交于
      PR #5210 added a Friendship model to illustrate a bug, but in doing so
      created a confusing structure because both belongs_to declarations in
      Friendship referred to the same side of the join. The new structure
      maintains the integrity of the bug test while changing the follower
      relationship to be more useful for other testing.
      1d6eabb6
  13. 08 3月, 2013 1 次提交
  14. 28 2月, 2013 1 次提交
  15. 26 2月, 2013 1 次提交
  16. 07 2月, 2013 1 次提交
  17. 28 1月, 2013 1 次提交
    • J
      Prevent Relation#merge from collapsing wheres on the RHS · c8d88990
      Jon Leighton 提交于
      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
      c8d88990
  18. 22 12月, 2012 1 次提交
  19. 11 12月, 2012 1 次提交
  20. 16 11月, 2012 1 次提交
  21. 26 10月, 2012 1 次提交
    • J
      Remove ActiveRecord::Model · 9e4c41c9
      Jon Leighton 提交于
      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.
      9e4c41c9
  22. 02 10月, 2012 1 次提交
  23. 12 9月, 2012 1 次提交
    • B
      Accept belongs_to assoc. keys in ActiveRecord queries · 3da275c4
      beerlington 提交于
      Allows you to specify the model association key in a belongs_to
      relationship instead of the foreign key.
      
      The following queries are now equivalent:
      
      Post.where(:author_id => Author.first)
      Post.where(:author => Author.first)
      
      PriceEstimate.where(:estimate_of_type => 'Treasure', :estimate_of_id => treasure)
      PriceEstimate.where(:estimate_of => treasure)
      3da275c4
  24. 06 9月, 2012 1 次提交
  25. 04 9月, 2012 2 次提交
  26. 03 9月, 2012 1 次提交
    • Y
      set the configured #inheritance_column on #become (#7503) · 20574956
      Yves Senn 提交于
      I had to create a new table because I needed an STI table,
      which does not have both a "type" and a "custom_type"
      
      the test fails with:
        1) Error:
      test_alt_becomes_works_with_sti(InheritanceTest):
      NoMethodError: undefined method `type=' for #<Cabbage id: 1, name: "my cucumber", custom_type: "Cucumber">
          /Users/username/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:432:in `method_missing'
          /Users/username/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:100:in `method_missing'
          /Users/username/Projects/rails/activerecord/lib/active_record/persistence.rb:165:in `becomes'
          test/cases/inheritance_test.rb:134:in `test_becomes_works_with_sti'
          test/cases/inheritance_test.rb:140:in `test_alt_becomes_works_with_sti'
      20574956
  27. 22 8月, 2012 1 次提交
  28. 28 7月, 2012 1 次提交
  29. 27 7月, 2012 1 次提交
  30. 26 7月, 2012 1 次提交
  31. 25 7月, 2012 1 次提交
  32. 25 6月, 2012 1 次提交
    • P
      Revert "Merge pull request #6344" · ceb68d18
      Piotr Sarnacki 提交于
      This commit needs to be reverted because it introduces difficulties when
      using sqlite3 in development and other databases in production. This
      happens because when you create time column in sqlite3, it's dumped as
      datetime in schema.rb file.
      
      This reverts commit 57d534ee, reversing
      changes made to 20f049fb.
      
      Conflicts:
      
      	activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
      ceb68d18
  33. 22 6月, 2012 1 次提交
    • A
      Improve the derivation of HABTM assocation join table names · 46492949
      Andrew White 提交于
      Improve the derivation of HABTM join table name to take account of nesting.
      It now takes the table names of the two models, sorts them lexically and
      then joins them, stripping any common prefix from the second table name.
      
      Some examples:
      
        Top level models
        (Category <=> Product)
        Old: categories_products
        New: categories_products
      
        Top level models with a global table_name_prefix
        (Category <=> Product)
        Old: site_categories_products
        New: site_categories_products
      
        Nested models in a module without a table_name_prefix method
        (Admin::Category <=> Admin::Product)
        Old: categories_products
        New: categories_products
      
        Nested models in a module with a table_name_prefix method
        (Admin::Category <=> Admin::Product)
        Old: categories_products
        New: admin_categories_products
      
        Nested models in a parent model
        (Catalog::Category <=> Catalog::Product)
        Old: categories_products
        New: catalog_categories_products
      
        Nested models in different parent models
        (Catalog::Category <=> Content::Page)
        Old: categories_pages
        New: catalog_categories_content_pages
      
      Also as part of this commit the validity checks for HABTM assocations have
      been moved to ActiveRecord::Reflection One side effect of this is to move when
      the exceptions are raised from the point of declaration to when the association
      is built. This is consistant with other association validity checks.
      46492949
  34. 16 5月, 2012 1 次提交
  35. 14 5月, 2012 1 次提交
  36. 10 5月, 2012 1 次提交