Skip to content

fix-finding-query-methods #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

picandocodigo
Copy link
Member

Transferred from elastic/elasticsearch-ruby#855:

Original Pull Request message:

Queirs.const_defined? 'Foo' find not only Queries::Foo but also ::Foo,
so if program has Foo class, this method_missing call Foo.new instead of call foo method.

class Foo
   include ActiveModel::Model
   include ActiveModel::Attributes

   attribute :name, :string
end

class SearchForm
  include ActiveModel::Model
  include ActiveModel::Attributes
  include Elasticsearch::DSL

  attribute :foo

  def condition
    search do
      query do
        bool { must { term name: foo.name } }
      end
    end
  end
end

p SearchForm.new(foo: Foo.new(name: 'hello')).condition.to_hash
  • expect: {:query=>{:bool=>{:must=>[{:term=>{:name=>"name"}}]}}}
  • actual: {:query=>{:bool=>{:must=>[{:term=>{:name=>nil}}]}}}

`Queirs.const_defined? 'Foo'` find not only `Queries::Foo` but also `::Foo`,
so if program has `Foo` class, this `method_missing` call `Foo.new` instead of call `foo` method.
@picandocodigo
Copy link
Member Author

picandocodigo commented Jan 13, 2022

@masarakki would it be possible for you to add a test for this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants