@@ -2096,7 +2096,7 @@ defmodule Ecto.Schema do
20962096 :ok
20972097 end
20982098
2099- @ valid_has_options [
2099+ @ valid_has_many_options [
21002100 :foreign_key ,
21012101 :references ,
21022102 :through ,
@@ -2110,22 +2110,32 @@ defmodule Ecto.Schema do
21102110 @ doc false
21112111 def __has_many__ ( mod , name , queryable , opts ) do
21122112 if is_list ( queryable ) and Keyword . has_key? ( queryable , :through ) do
2113- check_options! ( queryable , @ valid_has_options , "has_many/3" )
2113+ check_options! ( queryable , @ valid_has_many_options , "has_many/3" )
21142114 association ( mod , :many , name , Ecto.Association.HasThrough , queryable )
21152115 else
2116- check_options! ( opts , @ valid_has_options , "has_many/3" )
2116+ check_options! ( opts , @ valid_has_many_options , "has_many/3" )
21172117 struct = association ( mod , :many , name , Ecto.Association.Has , [ queryable: queryable ] ++ opts )
21182118 Module . put_attribute ( mod , :ecto_changeset_fields , { name , { :assoc , struct } } )
21192119 end
21202120 end
21212121
2122+ @ valid_has_one_options [
2123+ :foreign_key ,
2124+ :references ,
2125+ :through ,
2126+ :on_delete ,
2127+ :defaults ,
2128+ :on_replace ,
2129+ :where
2130+ ]
2131+
21222132 @ doc false
21232133 def __has_one__ ( mod , name , queryable , opts ) do
21242134 if is_list ( queryable ) and Keyword . has_key? ( queryable , :through ) do
2125- check_options! ( queryable , @ valid_has_options , "has_one/3" )
2135+ check_options! ( queryable , @ valid_has_one_options , "has_one/3" )
21262136 association ( mod , :one , name , Ecto.Association.HasThrough , queryable )
21272137 else
2128- check_options! ( opts , @ valid_has_options , "has_one/3" )
2138+ check_options! ( opts , @ valid_has_one_options , "has_one/3" )
21292139 struct = association ( mod , :one , name , Ecto.Association.Has , [ queryable: queryable ] ++ opts )
21302140 Module . put_attribute ( mod , :ecto_changeset_fields , { name , { :assoc , struct } } )
21312141 end
0 commit comments