Add an attribute check to the belongs_to resolution chain #50

Merged
merged 1 commit into from Feb 27, 2013

Conversation

Projects
None yet
2 participants
Contributor

denzel-morris commented Feb 12, 2013

Given a resource

class Resource < ActiveResource::Base
  belongs_to :owner
end

And the following JSON return

r = Resource.first 
=> {
  ...
  "owner": {
    ...
  }
}

Current Behavior

A NoMethodError is raised when trying to access the owner on the resource because the association attempts to find and use owner_id which isn't present.

r.owner 
=> NoMethodError ...

Desired Behavior

My patch makes the belongs to association behave like the others. It will look for the association name in the attributes before attempting to load it from the endpoint. Giving:

r.owner 
=> #<Owner:...>

guilleiguaran merged commit a5b90c5 into rails:master Feb 27, 2013

1 check passed

default The Travis build passed
Details

marktran referenced this pull request in adore/daylight Jan 17, 2015

Open

Attribute check for belongs_to resolution #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment