rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.09k stars 161 forks source link

Failed to find relation class for sql adapter. #358

Closed alexandru-calinoiu closed 8 years ago

alexandru-calinoiu commented 8 years ago

Trying to learn more about rom so I am working through the guides in fresh ruby gem project. I can't seem to figure out how to define my relations in separate files.

I have a relation defined like this:

      class Users < ROM::Relation[:sql]
        schema(infer: true) do
          associations do
            has_many :tasks
          end
        end

        def listing
          select(:id, :name, :email).order(:name)
        end
      end

But of course when I require it in it fails with: 'Failed to find relation class for sql adapter. Make sure ROM setup was started and the adapter identifier is correct.'

Does this mean I have to have a finalized container before I try to load the file?

solnic commented 8 years ago

You need either start setup prior requiring your relation classes, or at least require rom-sql manually yourself. Lemme know if that works. This should be better explained, probably a small standalone example would be best.

alexandru-calinoiu commented 8 years ago

I still can't get it working, maybe I don't understand the role of relations. I've pushed the project I am working on here https://github.com/alexandru-calinoiu/rom-test

I am basically trying to get https://github.com/alexandru-calinoiu/rom-test/blob/master/spec/rom/test/repositories/posts_repo_spec.rb this spec to pass or at least run.

alexandru-calinoiu commented 8 years ago

I guess what I am trying to achive is this part of the relations docs: You can put them in separate files, namespace them or not, and configure them when it's needed

alexandru-calinoiu commented 8 years ago

Found config.auto_registration in ROM::Configuration and tried to use that now the error is ROM::Registry::ElementNotFoundError: :posts doesn't exist in ROM::RelationRegistry registry it still seems that he relation does not get picked up :(

solnic commented 8 years ago

@alexandru-calinoiu I'll set it up for you in a couple hours

alexandru-calinoiu commented 8 years ago

Later ...

I finally figured this out, turns out the auto_registration has some dirs that it searches for relations in.

Opened a pr to sequel in the mean time also https://github.com/jeremyevans/sequel/pull/1250 :)

It still does not feel right improvements are welcomed.

solnic commented 8 years ago

@alexandru-calinoiu yeah in 2.0.0 it needs (relations|commands|mappers)/**/*.rb structure, but in 2.0.1 it's gonna be more flexible and configurable (it's already done in master)

solnic commented 8 years ago

OK so I'm gonna close this one. I'll add a simple setup example to the docs along with a repo on github, this should help in cases like yours.

alexandru-calinoiu commented 8 years ago

Thanks, I believe that a slight improvement on this part of the docs will help a lot.

mihairadulescu commented 7 years ago

i had a similar issue like you @alexandru-calinoiu and i added in my repository relations :pots