1. 17 10月, 2018 4 次提交
  2. 16 10月, 2018 1 次提交
  3. 13 10月, 2018 1 次提交
    • D
      Improve model attribute accessor method names for backtraces · 99c87ad2
      Dylan Thacker-Smith 提交于
      Ruby uses the original method name, so will show the __temp__ method
      name in the backtrace. However, in the common case the method name
      is compatible with the `def` keyword, so we can avoid the __temp__
      method name in that case to improve the name shown in backtraces
      or TracePoint#method_id.
      99c87ad2
  4. 11 10月, 2018 1 次提交
    • E
      Basic API for connection switching · 31021a8c
      Eileen Uchitelle 提交于
      This PR adds the ability to 1) connect to multiple databases in a model,
      and 2) switch between those connections using a block.
      
      To connect a model to a set of databases for writing and reading use
      the following API. This API supercedes `establish_connection`. The
      `writing` and `reading` keys represent handler / role names and
      `animals` and `animals_replica` represents the database key to look up
      the configuration hash from.
      
      ```
      class AnimalsBase < ApplicationRecord
        connects_to database: { writing: :animals, reading: :animals_replica }
      end
      ```
      
      Inside the application - outside the model declaration - we can switch
      connections with a block call to `connected_to`.
      
      If we want to connect to a db that isn't default (ie readonly_slow) we
      can connect like this:
      
      Outside the model we may want to connect to a new database (one that is
      not in the default writing/reading set) - for example a slow replica for
      making slow queries. To do this we have the `connected_to` method that
      takes a `database` hash that matches the signature of `connects_to`. The
      `connected_to` method also takes a block.
      
      ```
      AcitveRecord::Base.connected_to(database: { slow_readonly: :primary_replica_slow }) do
        ModelInPrimary.do_something_thats_slow
      end
      ```
      
      For models that are already loaded and connections that are already
      connected, `connected_to` doesn't need to pass in a `database` because
      you may want to run queries against multiple databases using a specific
      role/handler.
      
      In this case `connected_to` can take a `role` and use that to swap on
      the connection passed. This simplies queries - and matches how we do it
      in GitHub. Once you're connected to the database you don't need to
      re-connect, we assume the connection is in the pool and simply pass the
      handler we'd like to swap on.
      
      ```
      ActiveRecord::Base.connected_to(role: :reading) do
        Dog.read_something_from_dog
        ModelInPrimary.do_something_from_model_in_primary
      end
      ```
      31021a8c
  5. 10 10月, 2018 4 次提交
  6. 09 10月, 2018 2 次提交
    • R
      Generate delegation methods to named scope in the definition time · 136b738c
      Ryuta Kamizono 提交于
      The delegation methods to named scope are defined when `method_missing`
      is invoked on the relation.
      
      Since #29301, the receiver in the named scope is changed to the relation
      like others (e.g. `default_scope`, etc) for consistency.
      
      Most named scopes would be delegated from relation by `method_missing`,
      since we don't allow scopes to be defined which conflict with instance
      methods on `Relation` (#31179). But if a named scope is defined with the
      same name as any method on the `superclass` (e.g. `Kernel.open`), the
      `method_missing` on the relation is not invoked.
      
      To address the issue, make the delegation methods to named scope is
      generated in the definition time.
      
      Fixes #34098.
      136b738c
    • G
      Move db:migrate:status to DatabaseTasks method · 0d435c17
      Gannon McGibbon 提交于
      0d435c17
  7. 08 10月, 2018 2 次提交
  8. 07 10月, 2018 2 次提交
    • R
      Don't expose internal methods in the associations · 0b4cfa2b
      Ryuta Kamizono 提交于
      0b4cfa2b
    • R
      Fix `AssociationRelation` not to set inverse instance key just like before · 1f8534ca
      Ryuta Kamizono 提交于
      Since #31575, `set_inverse_instance` replaces the foreign key by the
      current owner immediately to make it happen when a record is added to
      collection association.
      
      But `set_inverse_instance` is not only called when a record is added,
      but also when a record is loaded from queries. And also, that loaded
      records are not always associated records for some reason (using `or`,
      `unscope`, `rewhere`, etc).
      
      It is hard to distinguish whether or not we should invoke
      `set_inverse_instance`, but at least we should avoid the undesired
      side-effect which was brought from #31575.
      
      Fixes #34108.
      1f8534ca
  9. 06 10月, 2018 6 次提交
  10. 04 10月, 2018 3 次提交
  11. 03 10月, 2018 2 次提交
  12. 02 10月, 2018 1 次提交
  13. 01 10月, 2018 1 次提交
  14. 30 9月, 2018 2 次提交
  15. 29 9月, 2018 2 次提交
    • Y
      Add `Style/RedundantFreeze` to remove redudant `.freeze` · aa3dcabd
      Yasuo Honda 提交于
      Since Rails 6.0 will support Ruby 2.4.1 or higher
      `# frozen_string_literal: true` magic comment is enough to make string object frozen.
      This magic comment is enabled by `Style/FrozenStringLiteralComment` cop.
      
      * Exclude these files not to auto correct false positive `Regexp#freeze`
       - 'actionpack/lib/action_dispatch/journey/router/utils.rb'
       - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'
      
      It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333
      Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed.
      
      * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required
      
       - 'actionpack/test/controller/test_case_test.rb'
       - 'activemodel/test/cases/type/string_test.rb'
       - 'activesupport/lib/active_support/core_ext/string/strip.rb'
       - 'activesupport/test/core_ext/string_ext_test.rb'
       - 'railties/test/generators/actions_test.rb'
      aa3dcabd
    • G
      4775d3d0
  16. 28 9月, 2018 4 次提交
    • B
      Bugfix ActiveRecord::Relation#merge special case of from clause · d76e3e12
      Bogdan Gusiev 提交于
      When one relation is merged into another that has a different base class
      merging `from_clause` causes invalid SQL to be generated
      d76e3e12
    • R
      Extract `Arel.arel_node?` helper method · d0d1cd3d
      Ryuta Kamizono 提交于
      d0d1cd3d
    • R
      Make `update_counters` preparable · e5190aca
      Ryuta Kamizono 提交于
      Before:
      
      ```
        Topic Update All (0.4ms)  UPDATE `topics` SET `topics`.`replies_count` = COALESCE(`topics`.`replies_count`, 0) + 1, `topics`.`updated_at` = '2018-09-27 18:34:05.068774' WHERE `topics`.`id` = ?  [["id", 7]]
      
      ```
      
      After:
      
      ```
        Topic Update All (0.4ms)  UPDATE `topics` SET `topics`.`replies_count` = COALESCE(`topics`.`replies_count`, 0) + ?, `topics`.`updated_at` = ? WHERE `topics`.`id` = ?  [["replies_count", 1], ["updated_at", 2018-09-27 18:55:05 UTC], ["id", 7]]
      
      ```
      e5190aca
    • R
      Make `update_all` preparable · 8e123847
      Ryuta Kamizono 提交于
      Before:
      
      ```
        Pet Update All (0.8ms)  UPDATE `pets` LEFT OUTER JOIN `toys` ON `toys`.`pet_id` = `pets`.`pet_id` SET `pets`.`name` = 'Bob' WHERE `toys`.`name` = ?  [["name", "Bone"]]
      ```
      
      After:
      
      ```
        Pet Update All (1.1ms)  UPDATE `pets` LEFT OUTER JOIN `toys` ON `toys`.`pet_id` = `pets`.`pet_id` SET `pets`.`name` = ? WHERE `toys`.`name` = ?  [["name", "Bob"], ["name", "Bone"]]
      ```
      8e123847
  17. 27 9月, 2018 2 次提交