Skip to content

Commit 40a598b

Browse files
committed
Add more complex filter example, showing the use of verify & apply
1 parent b95f613 commit 40a598b

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,24 @@ verified value, which may be modified.
701701
verify_keys(values, context)
702702
return values
703703
},
704-
apply: -> (records, value, _options) {
704+
apply: ->(records, value, _options) {
705705
records.where('id IN (?)', value)
706706
}
707707
```
708708

709+
```ruby
710+
# A more complex example, showing how to filter for any overlap between the
711+
# value array and the possible_ids, using both verify and apply callables.
712+
713+
filter :possible_ids,
714+
verify: ->(values, context) {
715+
values.map {|value| value.to_i}
716+
},
717+
apply: ->(records, value, _options) {
718+
records.where('possible_ids && ARRAY[?]', value)
719+
}
720+
```
721+
709722
##### Finders
710723

711724
Basic finding by filters is supported by resources. This is implemented in the `find` and `find_by_key` finder methods.

0 commit comments

Comments
 (0)