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

Nested scopes #198

Closed
AlexParamonov opened this issue Feb 15, 2015 · 5 comments
Closed

Nested scopes #198

AlexParamonov opened this issue Feb 15, 2015 · 5 comments

Comments

@AlexParamonov
Copy link
Contributor

Hello.

It would be great to do

parameter :links, "Linked objects", scope: :articles
parameter :author, "Author id", scope: :links

http://jsonapi.org/format/#crud-updating-relationships

@oestrich
Copy link
Contributor

This could be cool. When I get time I will look into this.

@juniorjp
Copy link

Hi. I was just looking into this, any workaround?

@xdmx
Copy link

xdmx commented Aug 5, 2015

👍 on this
maybe something like this?

parameter :links, "Linked objects", scope: :articles
parameter :author, "Author id", scope: [:articles, :links]

@kevintraver
Copy link
Contributor

Perhaps something like this:

parameter :author, "Author id", scope: { :articles => :links }

and then do some sort of merge into the existing hash

def set_param(hash, param)
  key = param[:name]
  return hash if !respond_to?(key) || in_path?(key)

  scope = param[:scope]
  if scope
    if scope.is_a?(Hash)
      # somehow merge into hash
    else
      hash[scope.to_s] ||= {}
      hash[scope.to_s][key] = send(key)
    end
  else
    hash[key] = send(key)
  end

  hash
end

def set_param(hash, param)
key = param[:name]
return hash if !respond_to?(key) || in_path?(key)
if param[:scope]
hash[param[:scope].to_s] ||= {}
hash[param[:scope].to_s][key] = send(key)
else
hash[key] = send(key)
end

@oestrich
Copy link
Contributor

Closed with #221

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

5 participants