开发者

Defining models with Mongoid for this database structure

Hey I'm trying to build a rails 3 app with Mongoid (for MongoDB). What I'm now trying to do:


Languages:

id (automatically crea开发者_Python百科ted, right?)

name (e.g. English)

code (e.g. en_US)

Languages_Texts:

id (see above...)

name (e.g. hello_world)

Translations:

id (see above...)

translation (e.g. Hello, world!)


I hope this database schema is understandable and not too bad. ;)

Now my problem is, that I don't know how to do this with a mongoid model in rails 3.

Anyone that could help me?

Thanks already!

Matthias


Looks like all you need is three different models, language, languages_text, and translation. The models should look like this

class Language
  include Mongoid::Document
  field :name
  field :code
end

class LanguagesText
  include Mongoid::Document
  field :name
end

class Translation
  include Mongoid::Document
  field :translation
end

This will put the data in different collections within the mongodb. Hope that helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜