doc/mass_assignment.rdoc in sequel-3.33.0 vs doc/mass_assignment.rdoc in sequel-3.34.0

- old
+ new

@@ -34,11 +34,11 @@ # Class level Post.strict_param_setting = false # Instance level post.strict_param_setting = false -These mass assignment methods have been around a long time, but starting in Sequel 3.12.0, the +set_fields+ or +update_fields+ methods were added, and these may be a better mass assignment choice for most users. +These mass assignment methods have been around a long time, but starting in Sequel 3.12.0, the +set_fields+ and +update_fields+ methods were added, and these may be a better mass assignment choice for most users. These methods take two arguments, the attributes hash as the first argument, and a single array of valid field names as the second argument: post.set_fields(params[:post], [:title, :body]) +set_fields+ and +update_fields+ differ in implementation from +set_only+ and +update_only+. @@ -47,8 +47,10 @@ +set_fields+ and +update_fields+ are designed for the case where you are expecting specific fields in the input, and want to ignore the other fields. They work great for things like HTML forms where the form fields are static. +set_only+ and +update_only+ are designed for cases where you are not sure what fields are going to be present in the input, but still want to make sure only certain setter methods can be called. They work great for flexible APIs. + +Starting in Sequel 3.34.0, +set_fields+ and +update_fields+ take an optional argument hash, and currently handles the :missing option. With <tt>:missing=>:skip</tt>, +set_fields+ and +update_fields+ will just skip missing entries in the hash, allowing them to be used in flexible APIs. With <tt>:missing=>:raise</tt>, +set_fields+ and +update_fields+ will raise an error if one of the entries in the hash is missing, instead of just assigning the value to nil or whatever the hash's default value is. That allows stricter checks, similar to the :strict_param_checking setting for the default mass assignment methods. In all of the mass assignment cases, methods starting with +set+ will set the attributes without saving the object, while methods starting with +update+ will set the attributes and then save the changes to the object.