Created
November 27, 2012 14:28
-
-
Save erubboli/4154503 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 'ohm' | |
require 'ohm/json' | |
module MyModule | |
class User < Ohm::Model | |
set :posts, :Post | |
attribute :name | |
def to_hash | |
super.merge( :name => name) | |
end | |
end | |
class Post < Ohm::Model | |
attribute :value | |
def to_hash | |
super.merge( :value => value) | |
end | |
end | |
end | |
Ohm.connect | |
u= MyModule::User.create(name: 'enrico') | |
u.posts.add MyModule::Post.create(value: 'something') | |
u.posts.add MyModule::Post.create(value: 'something else') | |
p u.posts.to_json | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment