Created
April 27, 2016 12:15
-
-
Save solnic/94b9e952b75b1f4605103c9e2f44515b to your computer and use it in GitHub Desktop.
This file contains 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
class Users < ROM::Relation[:users] | |
schema do | |
attribute :id, Types::Serial | |
attribute :name, Types::String | |
associate do | |
many :posts | |
end | |
end | |
end | |
class Posts < ROM::Relation[:posts] | |
schema do | |
attribute :id, Types::Serial | |
attribute :user_id, Types::ForeignKey(:users) | |
attribute :title, Types::String | |
attribute :body, Types::String | |
associate do | |
many :tags, through: :posts_tags | |
end | |
end | |
end | |
class UserRepo < ROM::Repository[:users] | |
end | |
class PostRepo < ROM::Repository[:posts] | |
end | |
user_repo = UserRepo.new(rom_container) | |
post_repo = PostRepo.new(rom_container) | |
user_repo.aggregate(:posts) # returns users with their posts | |
post_repo.aggregate(:tags) # returns posts with their tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment