theablefew / stretchy

Elasticsearch Models for Rails with an ActiveRecord-like behavior
https://theablefew.github.io/stretchy/#/
MIT License
2 stars 0 forks source link

Ensure attribute types map to elasticsearch datatypes #75

Closed esmarkowski closed 6 months ago

esmarkowski commented 6 months ago
class Report < StretchyModel
    attribute :title, :string
    attribute :published_on, :datetime
    attribute :created_by, :keyword
    attribute :body, :text, term_vector: :with_positions_offsets
end

:string and :datetime aren't valid elasticsearch datatypes.

Attributes::Type::Base defines type_for_database and should be implemented in subclasses that need a different type than their default.

  class DateTime < Stretchy::Attributes::Type::Base
    def type_for_database
      :date
    end
  end