@@ -1916,8 +1916,11 @@ defmodule Ecto.Changeset do
19161916
19171917 This function is used to work with associations as a whole. For example,
19181918 if a Post has many Comments, it allows you to add, remove or change all
1919- comments at once. If your goal is to simply add a new comment to a post,
1920- then it is preferred to do so manually, as we will describe later in the
1919+ comments at once, automatically computing inserts/updates/deletes by
1920+ comparing the data that you gave with the one already in the database.
1921+ If your goal is to manage individual resources, such as adding a new
1922+ comment to a post, or update post linked to a comment, tnen it is not
1923+ necessary to use this function. We will explore this later in the
19211924 ["Example: Adding a comment to a post" section](#put_assoc/4-example-adding-a-comment-to-a-post).
19221925
19231926 This function requires the associated data to have been preloaded, except
@@ -3256,23 +3259,75 @@ defmodule Ecto.Changeset do
32563259 result = Decimal . compare ( value , target_value )
32573260
32583261 case decimal_compare ( result , spec_key ) do
3259- true -> nil
3260- false -> [ { field , message ( opts , default_message , validation: :number , kind: spec_key , number: target_value ) } ]
3262+ true ->
3263+ nil
3264+
3265+ false ->
3266+ [
3267+ { field ,
3268+ message ( opts , default_message ,
3269+ validation: :number ,
3270+ kind: spec_key ,
3271+ number: target_value
3272+ ) }
3273+ ]
32613274 end
32623275 end
32633276
3264- defp compare_numbers ( field , value , default_message , spec_key , spec_function , % Decimal { } = target_value , opts ) do
3265- compare_numbers ( field , decimal_new ( value ) , default_message , spec_key , spec_function , target_value , opts )
3277+ defp compare_numbers (
3278+ field ,
3279+ value ,
3280+ default_message ,
3281+ spec_key ,
3282+ spec_function ,
3283+ % Decimal { } = target_value ,
3284+ opts
3285+ ) do
3286+ compare_numbers (
3287+ field ,
3288+ decimal_new ( value ) ,
3289+ default_message ,
3290+ spec_key ,
3291+ spec_function ,
3292+ target_value ,
3293+ opts
3294+ )
32663295 end
32673296
3268- defp compare_numbers ( field , % Decimal { } = value , default_message , spec_key , spec_function , target_value , opts ) do
3269- compare_numbers ( field , value , default_message , spec_key , spec_function , decimal_new ( target_value ) , opts )
3297+ defp compare_numbers (
3298+ field ,
3299+ % Decimal { } = value ,
3300+ default_message ,
3301+ spec_key ,
3302+ spec_function ,
3303+ target_value ,
3304+ opts
3305+ ) do
3306+ compare_numbers (
3307+ field ,
3308+ value ,
3309+ default_message ,
3310+ spec_key ,
3311+ spec_function ,
3312+ decimal_new ( target_value ) ,
3313+ opts
3314+ )
32703315 end
32713316
32723317 defp compare_numbers ( field , value , default_message , spec_key , spec_function , target_value , opts ) do
32733318 case apply ( spec_function , [ value , target_value ] ) do
3274- true -> nil
3275- false -> [ { field , message ( opts , default_message , validation: :number , kind: spec_key , number: target_value ) } ]
3319+ true ->
3320+ nil
3321+
3322+ false ->
3323+ [
3324+ { field ,
3325+ message ( opts , default_message ,
3326+ validation: :number ,
3327+ kind: spec_key ,
3328+ number: target_value
3329+ ) }
3330+ ]
32763331 end
32773332 end
32783333
0 commit comments