Skip to content
New issue

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

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

Already on GitHub? # to your account

Possibility to set up config in relation's definition #37

Open
firstsano opened this issue Dec 1, 2018 · 2 comments
Open

Possibility to set up config in relation's definition #37

firstsano opened this issue Dec 1, 2018 · 2 comments

Comments

@firstsano
Copy link

Is there a way to set default params for current relation? I want to be able not to include these kind of lines

.with_base_path('users')
.add_params(expand: 'account,account_details')

everywhere in current relation...

@solnic
Copy link
Member

solnic commented Dec 3, 2018

This is not supported yet, you can just handle it on your own for now by storing a pre-configured relation somewhere and use that at run-time. We could add a feature that would make this simpler.

@firstsano
Copy link
Author

Got it. So for now I think I'll use it as:

  class UsersRelation < ::ROM::Relation[:http]
    # schema definition goes here
    def by_id(id)
      base.with_path(id.to_s)
    end

    def all
      base.to_a
    end

    private

    def base
      with_base_path('users')
        .add_params(expand: 'account,account_details')
    end
  end

I'll try to help, maybe with PR, when I get more time.

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

No branches or pull requests

2 participants