Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The order of requiring gems shouldn't matter #2

Closed
jaredbeck opened this issue Aug 23, 2015 · 7 comments
Closed

The order of requiring gems shouldn't matter #2

jaredbeck opened this issue Aug 23, 2015 · 7 comments

Comments

@jaredbeck
Copy link

I'm following the repository guide (http://rom-rb.org/guides/basics/repositories/) as closely as I can, but I get an error on the first example.

UserRepository.new(rom).users.to_a

NameError: undefined local variable or method `attributes' 
for #<ROM::Repository::LoadingProxy:0x007fab0fd5c4d0>

rom/repository/loading_proxy.rb:168:in `method_missing'
rom/repository/loading_proxy.rb:58:in `to_ast'
rom/repository/loading_proxy.rb:79:in `mapper'

Piotr: repository isn’t handled automatically by the setup, yet
re error, it’s weird, I’ll try to reproduce it and fix, maybe you hit a bug, but that would be weird since that is a really basic example
maybe load-order was wrong
you need rom-sql and then rom-repository
there’s feature-detection logic so that sql is extended with plugins automatically
attributes are provided by one of the plugins so I’m pretty sure it’s the load order. try require "rom-sql” explicitly and then require “rom-repository”
I’ll update the guide and include that info, it’s pretty crucial

Changing the order of the gems in my Gemfile seems to do the trick though. The following seems to work.

gem 'rom-sql'
gem 'rom-repository'

Ideally, gems can be required in any order. If that can't be achieved, this problem is going to confuse a lot of people.

Piotr: pls report an issue .. Not sure how to fix that though but this should be addressed somehow

Thanks, I'd offer to help, but I'd be in way over my head. :)

@solnic
Copy link
Member

solnic commented Sep 3, 2015

This happens because that's what repository is doing now and it's a bit ugly.

We should probably introduce a setup specific for repository which will take care of extending relations. I don't see any other way. Check out #1 too, it's related.

@solnic
Copy link
Member

solnic commented Oct 14, 2015

This is now fixed. All plugins have been extracted to rom and rom-sql.

@solnic solnic closed this as completed Oct 14, 2015
@jaredbeck
Copy link
Author

This is now fixed.

Wooooo, thanks Piotr!

@solnic
Copy link
Member

solnic commented Oct 14, 2015

@jaredbeck :) I'm gonna push a release in a couple of days

@dwhelan
Copy link

dwhelan commented Jan 24, 2016

Hi, I am just getting started with ROM and when I tried out the memory adapter I got the same error with attributes not found:

/Users/Declan/.rvm/gems/ruby-2.2.3/gems/rom-repository-0.2.0/lib/rom/repository/loading_proxy.rb:172:in `method_missing': undefined local variable or method `attributes' for #<ROM::Repository::LoadingProxy:0x007fff33517130> (NameError)
        from /Users/Declan/.rvm/gems/ruby-2.2.3/gems/rom-repository-0.2.0/lib/rom/repository/loading_proxy.rb:62:in `to_ast'
        from /Users/Declan/.rvm/gems/ruby-2.2.3/gems/rom-repository-0.2.0/lib/rom/repository/loading_proxy.rb:83:in `mapper'
        from /Users/Declan/.rvm/gems/ruby-2.2.3/gems/rom-repository-0.2.0/lib/rom/repository/loading_proxy.rb:40:in `call'
        from /Users/Declan/.rvm/gems/ruby-2.2.3/gems/rom-1.0.0/lib/rom/relation/materializable.rb:20:in `to_a'
        from app.rb:34:in `<main>'

I'm not sure if I am doing something wrong ... here is my code:

require 'pry-byebug'
require 'rom'
require 'dry-data'
require 'rom-repository'
require 'rom-sql'

rom_container = ROM.container(:memory, 'memory://test') do |rom|
  rom.use :macros
  rom.relation :users
end

module Types
end

Dry::Data.configure do |config|
  config.namespace = Types
end

Dry::Data.finalize

class User < Dry::Data::Struct
  attribute :id,   Types::Int
  attribute :name, Types::String
end

class UserRepository < ROM::Repository
  relations :users
end

user_repo = UserRepository.new(rom_container)
dataset = user_repo.users.relation.dataset
dataset << { id: 1, name: 'Declan' }

p user_repo.users.as(User).to_a

I figured out how to get it working by adding the following lines to the ROM::Memory::Relation class:

      use :key_inference

      def attributes
        dataset.first ? dataset.first.keys : []
      end

I figured this out by trial and error and not at all sure if this is helpful or not as I don't really (yet) understand the design intent of the classes involved.

Do you have any suggestions for me to get this working without having to edit the ROM::Memory::Relation class?

And thanks for moving forward with ROM. It is an ambitious effort and I am thrilled you are tackling it.

P.S. I have attached my Gemfile.lock in case it helps.
Gemfile.lock.txt

@solnic
Copy link
Member

solnic commented Jan 24, 2016

@dwhelan sorry about that, I didn't make it anywhere clear that currently only rom-sql works with repositories out-of-the-box. I'll add a list of supported adapters to the docs.

@dwhelan
Copy link

dwhelan commented Jan 24, 2016

@solnic Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants