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) |
Author
replaid
commented
Aug 26, 2015
require 'rom'
require 'rom-sql'
ROM.use :auto_registration
ROM.setup(:sql, 'postgres://localhost/postgres')
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)
This works for me, where are you calling ROM.use :auto_registration
? It needs to be before relations/mappers/commands etc. are defined
Yes, I'm doing it as my first line of ROM code, in persist-rom.rb
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment