1. 02 11月, 2014 1 次提交
    • S
      Use bind values for joined tables in where statements · 10f75af9
      Sean Griffin 提交于
      In practical terms, this allows serialized columns and tz aware columns
      to be used in wheres that go through joins, where they previously would
      not behave correctly. Internally, this removes 1/3 of the cases where we
      rely on Arel to perform type casting for us.
      
      There were two non-obvious changes required for this. `update_all` on
      relation was merging its bind values with arel's in the wrong order.
      Additionally, through associations were assuming there would be no bind
      parameters in the preloader (presumably because the where would always
      be part of a join)
      
      [Melanie Gilman & Sean Griffin]
      10f75af9
  2. 29 10月, 2014 1 次提交
    • S
      💣 · 21f081c0
      Sean Griffin 提交于
      We were relying on hash inequality in tests
      21f081c0
  3. 06 9月, 2014 2 次提交
  4. 20 8月, 2014 1 次提交
  5. 13 8月, 2014 1 次提交
    • S
      Change the default `null` value for timestamps · ea3ba345
      Sean Griffin 提交于
      As per discussion, this changes the model generators to specify
      `null: false` for timestamp columns. A warning is now emitted if
      `timestamps` is called without a `null` option specified, so we can
      safely change the behavior when no option is specified in Rails 5.
      ea3ba345
  6. 16 7月, 2014 1 次提交
  7. 14 7月, 2014 1 次提交
  8. 06 7月, 2014 1 次提交
  9. 28 6月, 2014 3 次提交
  10. 27 6月, 2014 1 次提交
    • Y
      fk: use random digest names · 8768305f
      Yves Senn 提交于
      The name of the foreign key is not relevant from a users perspective.
      Using random names resolves the urge to rename the foreign key when the
      respective table or column is renamed.
      8768305f
  11. 26 6月, 2014 1 次提交
    • S
      Deprecate automatic counter caches on has_many :through · d730e374
      Sean Griffin 提交于
      Reliant on https://github.com/rails/rails/pull/15747 but pulled to a
      separate PR to reduce noise. `has_many :through` associations have the
      undocumented behavior of automatically detecting counter caches.
      However, the way in which it does so is inconsistent with counter caches
      everywhere else, and doesn't actually work consistently.
      
      As with normal `has_many` associations, the user should specify the
      counter cache on the `belongs_to`, if they'd like it updated.
      d730e374
  12. 20 6月, 2014 1 次提交
  13. 11 6月, 2014 1 次提交
  14. 10 6月, 2014 1 次提交
  15. 30 5月, 2014 1 次提交
  16. 27 5月, 2014 1 次提交
    • S
      Add a public API to allow users to specify column types · 65c33009
      Sean Griffin 提交于
      As a result of all of the refactoring that's been done, it's now
      possible for us to define a public API to allow users to specify
      behavior. This is an initial implementation so that I can work off of it
      in smaller pieces for additional features/refactorings.
      
      The current behavior will continue to stay the same, though I'd like to
      refactor towards the automatic schema detection being built off of this
      API, and add the ability to opt out of automatic schema detection.
      
      Use cases:
      
      - We can deprecate a lot of the edge cases around types, now that there
        is an alternate path for users who wish to maintain the same behavior.
      - I intend to refactor serialized columns to be built on top of this
        API.
      - Gem and library maintainers are able to interact with `ActiveRecord`
        at a slightly lower level in a more stable way.
      - Interesting ability to reverse the work flow of adding to the schema.
        Model can become the single source of truth for the structure. We can
        compare that to what the database says the schema is, diff them, and
        generate a migration.
      65c33009
  17. 23 5月, 2014 1 次提交
    • G
      Fixed serialization for records with an attribute named `format`. · 2d73f5ae
      Godfrey Chan 提交于
      * * *
      
      This bug can be triggered when serializing record R (the instance) of type C
      (the class), provided that the following conditions are met:
      
      1. The name of one or more columns/attributes on C/R matches an existing private
         method on C (e.g. those defined by `Kernel`, such as `format`).
      
      2. The attribute methods have not yet been generated on C.
      
      In this case, the matching private methods will be called by the serialization
      code (with no arguments) and their return values will be serialized instead. If
      the method requires one or more arguments, it will result in an `ArgumentError`.
      
      This regression is introduced in d1316bb1.
      
      * * *
      
      Attribute methods (e.g. `#name` and `#format`, assuming the class has columns
      named `name` and `format` in its database table) are lazily defined. Instead of
      defining them when a the class is defined (e.g. in the `inherited` hook on
      `ActiveRecord::Base`), this operation is deferred until they are first accessed.
      
      The reason behind this is that is defining those methods requires knowing what
      columns are defined on the database table, which usually requires a round-trip
      to the database. Deferring their definition until the last-possible moment helps
      reducing unnessary work, especially in development mode where classes are
      redefined and throw away between requests.
      
      Typically, when an attribute is first accessed (e.g. `a_book.format`), it will
      fire the `method_missing` hook on the class, which triggers the definition of
      the attribute methods. This even works for methods like `format`, because
      calling a private method with an explicit receiver will also trigger that hook.
      
      Unfortunately, `read_attribute_for_serialization` is simply an alias to `send`,
      which does not respect method visibility. As a result, when serializing a record
      with those conflicting attributes, the `method_missing` is not fired, and as a
      result the attribute methods are not defined one would expected.
      
      Before d1316bb1, this is negated by the fact that calling the `run_callbacks`
      method will also trigger a call to `respond_to?`, which is another trigger point
      for the class to define its attribute methods. Therefore, when Active Record
      tries to run the `after_find` callbacks, it will also define all the attribute
      methods thus masking the problem.
      
      * * *
      
      The proper fix for this problem is probably to restrict `read_attribute_for_serialization`
      to call public methods only (i.e. alias `read_attribute_for_serialization` to
      `public_send` instead of `send`). This however would be quite risky to change
      in a patch release and would probably require a full deprecation cycle.
      
      Another approach would be to override `read_attribute_for_serialization` inside
      Active Record to force the definition of attribute methods:
      
         def read_attribute_for_serialization(attribute)
           self.class.define_attribute_methods
           send(attribute)
         end
      
      Unfortunately, this is quite likely going to cause a performance degradation.
      
      This patch therefore restores the behaviour from the 4-0-stable branch by
      explicitly forcing the class to define its attribute methods in a similar spot
      (when records are initialized). This should not cause any extra roundtrips to
      the database because the `@columns` should already be cached on the class.
      
      Fixes #15188.
      2d73f5ae
  18. 21 5月, 2014 2 次提交
  19. 18 5月, 2014 1 次提交
  20. 13 5月, 2014 1 次提交
  21. 24 4月, 2014 1 次提交
    • J
      Fixes Issue #13466. · 9c3afdc3
      Jefferson Lai 提交于
      Changed the call to a scope block to be evaluated with instance_eval.
      The result is that ScopeRegistry can use the actual class instead of base_class when
      caching scopes so queries made by classes with a common ancestor won't leak scopes.
      9c3afdc3
  22. 05 4月, 2014 1 次提交
  23. 04 4月, 2014 1 次提交
    • Y
      PostgreSQL and SQLite, remove varchar limit. [Vladimir Sazhin & Toms Mikoss & Yves Senn] · f4226c3a
      Yves Senn 提交于
      There is no reason for the PG adapter to have a default limit of 255 on :string
      columns. See this snippet from the PG docs:
      
          Tip: There is no performance difference among these three types, apart
          from increased storage space when using the blank-padded type, and a
          few extra CPU cycles to check the length when storing into a
          length-constrained column. While character(n) has performance
          advantages in some other database systems, there is no such advantage
          in PostgreSQL; in fact character(n) is usually the slowest of the
          three because of its additional storage costs. In most situations text
          or character varying should be used instead.
      f4226c3a
  24. 03 4月, 2014 1 次提交
  25. 12 3月, 2014 1 次提交
  26. 24 2月, 2014 1 次提交
    • G
      Fixed STI classes not defining an attribute method if there is a · 41554319
      Godfrey Chan 提交于
      conflicting private method defined on its ancestors.
      
      The problem is that `method_defined_within?(name, klass, superklass)`
      only works correclty when `klass` and `superklass` are both `Class`es.
      
      If both `klass` and `superklass` are both `Class`es, they share the
      same inheritance chain, so if a method is defined on `klass` but not
      `superklass`, this method must be introduced at some point between
      `klass` and `superklass`.
      
      This does not work when `superklass` is a `Module`. A `Module`'s
      inheritance chain contains just itself. So if a method is defined on
      `klass` but not on `superklass`, the method could still be defined
      somewhere upstream, e.g. in `Object`.
      
      This fix works by avoiding calling `method_defined_within?` with a
      module while still fufilling the requirement (checking that the
      method is defined withing `superclass` but not is not a generated
      attribute method).
      
      4d8ee288 is likely an attempted partial fix for this problem. This
      unrolls that fix and properly check the `superclass` as intended.
      
      Fixes #11569.
      41554319
  27. 21 1月, 2014 1 次提交
  28. 14 1月, 2014 1 次提交
    • U
      Don't try to get the subclass if the inheritance column doesn't exist · e8d1d848
      Ujjwal Thaakar 提交于
      The `subclass_from_attrs` method is called even if the column specified by
      the `inheritance_column` setting doesn't exist. This prevents setting associations
      via the attributes hash if the association name clashes with the value of the setting,
      typically `:type`. This worked previously in Rails 3.2.
      e8d1d848
  29. 08 1月, 2014 1 次提交
  30. 06 1月, 2014 1 次提交
  31. 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
  32. 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
  33. 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
  34. 05 11月, 2013 1 次提交
  35. 04 11月, 2013 2 次提交