Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'rubygems'
require 'mongo_mapper'
MongoMapper.connection = Mongo::Connection.new('localhost',27017)
MongoMapper.database = "test"
class Word
include MongoMapper::Document
key :content, String
many :translations do
def sorted_by(something)
sort_by { |t| t.send(something) }
end
end
end
class Translation
include MongoMapper::EmbeddedDocument
key :content, String
key :lang, String
end
Word.collection.remove
w = Word.new(:content => "1")
w.translations << Translation.new(:content => "bala",:lang=>"pl")
w.translations << Translation.new(:content => "ara",:lang=>"en")
w.translations << Translation.new(:content => "sa",:lang=>"ja")
w.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment