@@ -486,6 +486,24 @@ defmodule Ecto.Schema do
486486 end
487487 end
488488
489+ @ field_opts [
490+ :default ,
491+ :source ,
492+ :autogenerate ,
493+ :read_after_writes ,
494+ :virtual ,
495+ :primary_key ,
496+ :load_in_query ,
497+ :redact ,
498+ :foreign_key ,
499+ :on_replace ,
500+ :defaults ,
501+ :type ,
502+ :where ,
503+ :references ,
504+ :skip_default_validation
505+ ]
506+
489507 @ doc """
490508 Defines an embedded schema with the given field definitions.
491509
@@ -1883,12 +1901,10 @@ defmodule Ecto.Schema do
18831901
18841902 @ doc false
18851903 def __field__ ( mod , name , type , opts ) do
1886- if type == :any and ! opts [ :virtual ] do
1887- raise ArgumentError , "only virtual fields can have type :any, " <>
1888- "invalid type for field #{ inspect name } "
1889- end
1890-
18911904 type = check_field_type! ( mod , name , type , opts )
1905+
1906+ opts = Keyword . put ( opts , :type , type )
1907+ check_options! ( opts , @ field_opts , "field/3" )
18921908 Module . put_attribute ( mod , :changeset_fields , { name , type } )
18931909 validate_default! ( type , opts [ :default ] , opts [ :skip_default_validation ] )
18941910 define_field ( mod , name , type , opts )
@@ -2161,15 +2177,27 @@ defmodule Ecto.Schema do
21612177 end
21622178
21632179 defp check_options! ( opts , valid , fun_arity ) do
2164- type = Keyword . get ( opts , :type )
2180+ case opts [ :type ] do
2181+ { :parameterized , _ , _ } ->
2182+ :ok
21652183
2166- if is_atom ( type ) and Code . ensure_compiled ( type ) == { :module , type } and function_exported? ( type , :type , 1 ) do
2167- :ok
2168- else
2169- case Enum . find ( opts , fn { k , _ } -> not ( k in valid ) end ) do
2170- { k , _ } -> raise ArgumentError , "invalid option #{ inspect k } for #{ fun_arity } "
2171- nil -> :ok
2172- end
2184+ { _ , { :parameterized , _ , _ } } ->
2185+ :ok
2186+
2187+ :any ->
2188+ if ! opts [ :virtual ] , do:
2189+ raise ArgumentError , "only virtual fields can have type :any, " <>
2190+ "invalid type for field #{ inspect opts [ :name ] } "
2191+
2192+ type ->
2193+ if is_atom ( type ) and Code . ensure_compiled ( type ) == { :module , type } and function_exported? ( type , :type , 1 ) do
2194+ :ok
2195+ else
2196+ case Enum . find ( opts , fn { k , _ } -> not ( k in valid ) end ) do
2197+ { k , _ } -> raise ArgumentError , "invalid option #{ inspect k } for #{ fun_arity } "
2198+ nil -> :ok
2199+ end
2200+ end
21732201 end
21742202 end
21752203
0 commit comments