Last active
August 26, 2015 22:26
-
-
Save replaid/7bf81921a45ae1791540 to your computer and use it in GitHub Desktop.
ROM Relation setup difficulty
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
require 'domain' | |
require 'persist/rom' | |
require 'persist/users_relation' | |
rom = ROM.env | |
p rom | |
Domain::Repository::User.delegate = rom.relation(:users).as(:user) |
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
require 'rom' | |
ROM.use(:auto_registration) | |
ROM.setup(:sql, 'postgres://localhost/apphf_dev') | |
ROM.finalize |
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
require 'persist/rom' | |
require 'rom-sql' | |
module Persist | |
class UsersRelation < ROM::Relation[:sql] | |
register_as :users | |
dataset :users | |
end | |
end |
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
require 'rubygems' | |
gem 'rom-sql' | |
ROM.setup(:sql, 'postgres://localhost/apphf_dev') | |
class UsersRelation < ROM::Relation[:sql] | |
dataset :users | |
end | |
class User | |
end | |
class UserEntityMapper < ROM::Mapper | |
relation :users | |
model User | |
end | |
rom = ROM.finalize.env | |
user_relation = rom.relation(:users) | |
mapped_user_relation = user_relation.as(:users) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, I'm doing it as my first line of ROM code, in
persist-rom.rb
.