class Quote < ActiveRecord::Base

  # my bone dry solution to search, sort and paginate
  include SearchSortPaginate

  define_index do
    indexes body
    has created_at, updated_at
  end

  belongs_to :user

  # we have a polymorphic relationship with notes
  has_many :notes, :as => :asset

  # the hash representing this model that is returned by the api
  def api_attributes
    {
      :id => id.to_s,
      :type => self.class.name.underscore.downcase,
      :body => body,
      :user => user.present? ? user.api_attributes : "",
    }
  end

   # Need to normalize the search attributes
  def search_attributes
    {:title => self.user.name, :description => self.body, :image => ''}
  end

  # a DRY approach to searching lists of these models
  def self.search_fields parent_model=nil
    case parent_model.class.name.underscore
    when 'foo'
    else
      [
        { :name => :created_at, :as => :datetimerange },
      ]
    end
  end

end
