Skip to content
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

Infinite recursion caused by as_indexed_json #51

Closed
aercolino opened this issue Mar 21, 2014 · 2 comments
Closed

Infinite recursion caused by as_indexed_json #51

aercolino opened this issue Mar 21, 2014 · 2 comments

Comments

@aercolino
Copy link

class Thing < ActiveRecord::Base
  include Elasticsearch::Model
  def as_indexed_json(options={})
    default = self.__elasticsearch__.as_indexed_json(options) # <--
    other = {
      # whatever
    }
    default.merge(other)
  end
end

Wanting to extend the default behavior (intuitive, DRY, OO) causes infinite recursion.

Soon I'll submit a pull request.

@karmi
Copy link
Contributor

karmi commented Mar 22, 2014

I don't see a good reason to call self.__elasticsearch__.as_indexed_json inside your own implementation. There is nothing special about that method, and you should simply implement it yourself, with the as_json provided by ActiveModel/ActiveSupport or by building the Hash.

@karmi
Copy link
Contributor

karmi commented Apr 15, 2014

@aercolino Hey, closing this, it's been some time. Let me repeat again, that there is no need whatsoever for you to call the self.__elasticsearch__.as_indexed_json method. Just serialize your model to a Hash with whatever means you have.

@karmi karmi closed this as completed Apr 15, 2014
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

No branches or pull requests

2 participants