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

Failed to find relation class for sql adapter. #358

Closed
alexandru-calinoiu opened this issue Oct 13, 2016 · 10 comments
Closed

Failed to find relation class for sql adapter. #358

alexandru-calinoiu opened this issue Oct 13, 2016 · 10 comments

Comments

@alexandru-calinoiu
Copy link

alexandru-calinoiu commented Oct 13, 2016

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
Copy link
Member

solnic commented Oct 13, 2016

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Member

solnic commented Oct 13, 2016

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

@alexandru-calinoiu
Copy link
Author

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 jeremyevans/sequel#1250 :)

It still does not feel right improvements are welcomed.

@solnic
Copy link
Member

solnic commented Oct 13, 2016

@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
Copy link
Member

solnic commented Oct 15, 2016

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
Copy link
Author

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

@mihairadulescu
Copy link

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

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