graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

howto invoke filter_string_match() function etc.

Open openxyz opened this issue 4 years ago • 1 comments

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

openxyz avatar Oct 03 '20 13:10 openxyz

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

wadetandy avatar Oct 03 '20 15:10 wadetandy