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

fix path option on belongs_to association #511

Merged
merged 1 commit into from
Oct 18, 2018
Merged

Conversation

zacharywelch
Copy link
Collaborator

@zacharywelch zacharywelch commented Oct 17, 2018

fixes #506

path option was being ignored on belongs_to associations and replaced with the default. According to the documentation

Options Hash (opts):
:path (Path) — The relative path where to fetch the data (defaults to /class_name.pluralize/id)

Example of the behavior

class User
  include Her::Model
  
  belongs_to :company, path: "/organizations/:id", 
                       foreign_key: :organization_id, 
                       data_key: :organization
end


class Company
  include Her::Model
end

Before

> user = User.find(1) 
# GET "/users/1", response is:
# {
#   "id": 1,
#   "name": "George Michael Bluth",
#   "organization_id": 2
# }

> user.company # goes to wrong path
# GET "/companies/2"

After

> user = User.find(1) 
# GET "/users/1", response is:
# {
#   "id": 1,
#   "name": "George Michael Bluth",
#   "organization_id": 2
# }

> user.company # goes to correct path
# GET "/organizations/2"

@zacharywelch zacharywelch merged commit a64ecaf into master Oct 18, 2018
@zacharywelch zacharywelch deleted the zw/belongs-to-path branch October 18, 2018 14:59
@edtjones
Copy link
Collaborator

Thanks as ever for being a hero @zacharywelch 👍

@seanbjornsson
Copy link

Thanks for the fix @zacharywelch !

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

Successfully merging this pull request may close these issues.

Belongs_to options are not used when building request
3 participants