Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Model#set_fields and update_fields, similar to set_only and updat…
…e_only but ignoring other keys in the hash set_fields and update_fields behave similarly to set_only and update_only with strict_param_setting set to false. That is, they only set the fields given, and ignore the other entries in the hash. They don't check the strict_param_setting flag, so if you have a hash that has other unrelated keys and you only want to use the keys you care about (and don't want to set strict_param_setting to false), this is the method to use. These methods don't use the framework the other set and update methods use, so if you try specify a field that doesn't have a setter method, you'll get a NoMethodError instead of a Sequel::Error. The other set and update methods try each entry in the hash and check if it is allowed, set_fields and update_fields just iterate through the given array. Another difference between the *_fields methods and the *_only methods is how they handle entries in the array that aren't in the hash. set_only will ignore the entries, since it iterates over the hash. set_fields will call the setter method with the default value of the hash (or whatever is returned by #[]), since it iterates over the array.
- Loading branch information
1 parent
d3a0f66
commit 9b28b3b
Showing
3 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters