Skip to content

Instantly share code, notes, and snippets.

@lgs
Created January 19, 2013 21:06
Show Gist options
  • Save lgs/4575131 to your computer and use it in GitHub Desktop.
Save lgs/4575131 to your computer and use it in GitHub Desktop.
RAILS_ENV=production rake environment tire:import CLASS=User FORCE=true
class User
include Mongoid::Document
include Tire::Model::Search
include Tire::Model::Callbacks
tire do
mapping do
indexes :nickname
indexes :watchlists do
indexes :description
indexes :html_url
indexes :tags
end
end
end
def to_indexed_json
{
:nickname => nickname,
:watchlists => watchlists.map { |c| { :_type => 'mongoid_watchlist',
:_id => c.id,
:description => c.description,
:html_url => c.html_url,
:tags => c.tags } }
}.to_json
end
field :nickname
embeds_many :watchlists
end
class Watchlist
include Mongoid::Document
field :description
field :html_url
field :tags
embedded_in :user
end
RAILS_ENV=production rake environment tire:import CLASS=User FORCE=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment