Created
January 6, 2009 09:52
-
-
Save drogus/43747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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