graphiti
graphiti copied to clipboard
howto invoke filter_string_match() function etc.
Graphiti::Adapters::ActiveRecord has some great function such as filter_string_match() etc.
but howto invoke it ?, for example:
filter :some_field do
match do | scope ,value |
filter_string_match(...) # can`t work
# my workround it ugly : Graphiti::Adapters::ActiveRecord.new self
end
end
These are by default what gets called under the hood when you have an attribute filtered by the specified operator:
class PostResource < ApplicationResource
attribute :title, :string, filterable: true
end
# https://myapi.com/v1/posts?filter[title][prefix]=hello
That will call filter_string_prefix
when it resolves. These are all available on the resource's adapter though, so if you need to invoke them directly for some reason, you should be able to do it:
filter :some_field do
match do | scope ,value |
self.adapter.filter_string_match(value)
end
end