Skip to content

Instantly share code, notes, and snippets.

@replaid
Last active August 26, 2015 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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)
@replaid
Copy link
Author

replaid commented Aug 26, 2015

$ ruby repro.rb
~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rom-support-0.1.0/lib/rom/support/registry.rb:30:in `block in []': :users doesn't exist in ROM::RelationRegistry registry (ROM::Registry::ElementNotFoundError)
    from ~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rom-support-0.1.0/lib/rom/support/registry.rb:30:in `fetch'
    from ~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rom-support-0.1.0/lib/rom/support/registry.rb:30:in `[]'
    from ~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rom-0.9.1/lib/rom/container.rb:71:in `relation'
    from repro.rb:36:in `<main>'

@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