Skip to content

Instantly share code, notes, and snippets.

@replaid
Last active August 26, 2015 22:26
Show Gist options
  • Save replaid/7bf81921a45ae1791540 to your computer and use it in GitHub Desktop.
Save replaid/7bf81921a45ae1791540 to your computer and use it in GitHub Desktop.
ROM Relation setup difficulty
require 'domain'
require 'persist/rom'
require 'persist/users_relation'
rom = ROM.env
p rom
Domain::Repository::User.delegate = rom.relation(:users).as(:user)
require 'rom'
ROM.use(:auto_registration)
ROM.setup(:sql, 'postgres://localhost/apphf_dev')
ROM.finalize
require 'persist/rom'
require 'rom-sql'
module Persist
class UsersRelation < ROM::Relation[:sql]
register_as :users
dataset :users
end
end
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)
@AMHOL
Copy link

AMHOL 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

@replaid
Copy link
Author

replaid commented Aug 26, 2015

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