Skip to content

Instantly share code, notes, and snippets.

@robertomiranda
Forked from lgs/tire:import CLASS=User
Last active August 29, 2015 14:15
Show Gist options
  • Save robertomiranda/fad0ac41703a67459e78 to your computer and use it in GitHub Desktop.
Save robertomiranda/fad0ac41703a67459e78 to your computer and use it in GitHub Desktop.
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