Skip to content

Instantly share code, notes, and snippets.

@drogus
Created January 6, 2009 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drogus/43747 to your computer and use it in GitHub Desktop.
Save drogus/43747 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default, 'sqlite3::memory:')
class Article
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
property :locale, String
belongs_to :link
end
class Link
include DataMapper::Resource
property :id, Serial
has n, :articles
# or a number of languages, if it`s fixed
end
DataMapper.auto_migrate!
article_en = Article.new(
:title => "ENGLISH article", :body => "english", :locale => 'en-EN' )
article_ru = Article.new(
:title => "RUSSIAN article", :body => "russian", :locale => 'ru-RU' )
link1 = Link.new
link1.articles << article_en << article_ru
link1.save
article_en = Article.new(
:title => "ENGLISH article #2", :body => "english #2", :locale => 'en-EN' )
article_ru = Article.new(
:title => "RUSSIAN article #2", :body => "russian #2", :locale => 'ru-RU' )
link2 = Link.new
link2.articles << article_en << article_ru
link2.save
puts link1.articles.first(:locale => 'ru-RU').inspect
puts link2.articles.first(:locale => 'ru-RU').inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment