提交 0fc11572 编写于 作者: A Andrew White 提交者: GitHub

Merge pull request #26693 from iainbeeston/consistently-use-activerecord-attributes

Made ActiveRecord consistently use ActiveRecord::Type (not ActiveModel::Type)
* Made ActiveRecord consistently use `ActiveRecord::Type` (not `ActiveModel::Type`)
*Iain Beeston*
* Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`
*Trung Duc Tran*
......
......@@ -19,7 +19,7 @@ def query_attribute(attr_name)
if Numeric === value || value !~ /[^0-9]/
!value.to_i.zero?
else
return false if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
return false if ActiveRecord::Type::Boolean::FALSE_VALUES.include?(value)
!value.blank?
end
elsif value.respond_to?(:zero?)
......
require "active_model/type"
require "active_record/type/helpers"
require "active_record/type/value"
require "active_record/type/internal/abstract_json"
require "active_record/type/internal/timezone"
......@@ -48,7 +50,6 @@ def current_adapter_name
end
end
Helpers = ActiveModel::Type::Helpers
BigInteger = ActiveModel::Type::BigInteger
Binary = ActiveModel::Type::Binary
Boolean = ActiveModel::Type::Boolean
......@@ -59,7 +60,6 @@ def current_adapter_name
String = ActiveModel::Type::String
Text = ActiveModel::Type::Text
UnsignedInteger = ActiveModel::Type::UnsignedInteger
Value = ActiveModel::Type::Value
register(:big_integer, Type::BigInteger, override: false)
register(:binary, Type::Binary, override: false)
......
module ActiveRecord
module Type
Helpers = ActiveModel::Type::Helpers
end
end
module ActiveRecord
module Type
module Internal # :nodoc:
class AbstractJson < ActiveModel::Type::Value # :nodoc:
include ActiveModel::Type::Helpers::Mutable
class AbstractJson < Type::Value # :nodoc:
include Type::Helpers::Mutable
def type
:json
......
module ActiveRecord
module Type
class Serialized < DelegateClass(ActiveModel::Type::Value) # :nodoc:
include ActiveModel::Type::Helpers::Mutable
class Serialized < DelegateClass(Type::Value) # :nodoc:
include Type::Helpers::Mutable
attr_reader :subtype, :coder
......
module ActiveRecord
module Type
class Value < ActiveModel::Type::Value; end
end
end
......@@ -313,8 +313,8 @@ def coder.load(value)
return if value.nil?
value.gsub(" encoded", "")
end
type = Class.new(ActiveModel::Type::Value) do
include ActiveModel::Type::Helpers::Mutable
type = Class.new(ActiveRecord::Type::Value) do
include ActiveRecord::Type::Helpers::Mutable
def serialize(value)
return if value.nil?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册