mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
allow passing false to :polymorphic option of belongs_to
before this, passing false would raise the following error because a condition in AR would disregard the option entirely if false was passed. ArgumentError: Unknown key: :polymorphic. Valid keys are: :class_name, :anonymous_class, :primary_key, :foreign_key, :dependent, :validate, :inverse_of, :strict_loading, :autosave, :required, :touch, :counter_cache, :optional, :default
This commit is contained in:
parent
c89632abf0
commit
5b2332ac71
3 changed files with 18 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
||||||
|
|
||||||
|
Previously, passing `false` would trigger the option validation logic
|
||||||
|
to throw an error saying :polymorphic would not be a valid option.
|
||||||
|
|
||||||
|
*glaszig*
|
||||||
|
|
||||||
* Remove deprecated `database` kwarg from `connected_to`.
|
* Remove deprecated `database` kwarg from `connected_to`.
|
||||||
|
|
||||||
*Eileen M. Uchitelle*, *John Crepezzi*
|
*Eileen M. Uchitelle*, *John Crepezzi*
|
||||||
|
|
|
@ -7,8 +7,8 @@ module ActiveRecord::Associations::Builder # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.valid_options(options)
|
def self.valid_options(options)
|
||||||
valid = super + [:counter_cache, :optional, :default]
|
valid = super + [:polymorphic, :counter_cache, :optional, :default]
|
||||||
valid += [:polymorphic, :foreign_type] if options[:polymorphic]
|
valid += [:foreign_type] if options[:polymorphic]
|
||||||
valid += [:ensuring_owner_was] if options[:dependent] == :destroy_async
|
valid += [:ensuring_owner_was] if options[:dependent] == :destroy_async
|
||||||
valid
|
valid
|
||||||
end
|
end
|
||||||
|
|
|
@ -1354,6 +1354,15 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
||||||
assert_equal toy, sponsor.reload.sponsorable
|
assert_equal toy, sponsor.reload.sponsorable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_polymorphic_with_false
|
||||||
|
assert_nothing_raised do
|
||||||
|
Class.new(ActiveRecord::Base) do
|
||||||
|
def self.name; "Post"; end
|
||||||
|
belongs_to :category, polymorphic: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "stale tracking doesn't care about the type" do
|
test "stale tracking doesn't care about the type" do
|
||||||
apple = Firm.create("name" => "Apple")
|
apple = Firm.create("name" => "Apple")
|
||||||
citibank = Account.create("credit_limit" => 10)
|
citibank = Account.create("credit_limit" => 10)
|
||||||
|
|
Loading…
Reference in a new issue