2014/04/23分のコミットです。
has_many :through
を使用した際に、unscope
が正常に動作してなかったバグの修正が行われています。
Merge pull request #14801 from kuldeepaggarwal/fix-string-inflection
String#pluralize
の振る舞いを修正しています。
pluralize
に引数に1を設定した場合は、self
を、それ以外の数字を設定した場合は新しいStringのインスタンスを返すようになっていたのを、引数に1を設定した場合も新しいStringのインスタンスを返すように修正しています。処理の一貫性の統一のためですね。
pluralize
に引数があるのは知らなかったです。1を指定した場合は単数形の値が返るのですね。
Merge pull request #14573 from habermann24/has_many_through_fix
has_many :through
を使用した際に、unscope
が正常に動作してなかったのを修正しています。
issueに記載されていたサンプルは以下のような形です。
class Account < ActiveRecord::Base cattr_accessor :current has_many :people, dependent: :destroy end class Person < ActiveRecord::Base belongs_to :account belongs_to :user default_scope { where(account_id: Account.current) if Account.current } scope :across_all_accounts, -> { unscope(where: :account_id) } end class User < ActiveRecord::Base has_many :identities, ->{ across_all_accounts }, class_name: 'Person' has_many :accounts, through: :identities end
# Account.current.id = 1 in this example current_user.identities.pluck(:account_id) User Load (1.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1 (0.5ms) SELECT "people"."account_id" FROM "people" WHERE "people"."user_id" = $1 [["user_id", 1]] => [3, 1] current_user.accounts.pluck(:id) User Load (1.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1 (0.6ms) SELECT "accounts"."id" FROM "accounts" INNER JOIN "people" ON "accounts"."id" = "people"."account_id" WHERE "people"."account_id" = 1 AND "people"."user_id" = $1 [["user_id", 1]] => [1]
二つ目は、scope :across_all_accounts
を指定しているのに、default_scope
が外れないというバグがあた為、正しくdefault_scope
が外れるよう修正しています。
Add CHANGELOG entry for #14757 [ci skip]
昨日あった、select!メソッドの名前の変更について、CHANGELOGに追記しています。
syntax errorの修正です。activerecord/test/cases/associations/has_many_through_associations_test.rb
にend
が足りてなかったので追加。
Perfer to define methods instead of calling test
activerecord/test/cases/associations/has_many_through_associations_test.rb
のテストの書き方を修正しています。
テストメソッドの書き方を、test xxxx
-> def test_xxxx
に修正しています。
activerecord
の既存のテストが後者の書き方なので、書き方統一の為ですね。
ActiveSupport::Inflector#constantize
のコメントの修正を行っています。