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

Has many fetch collection check #264

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dturnerTS
Copy link
Contributor

A get request that receives no data returns an instance. However, the fetch method has_many_association implicitly assumes it will receive a collection. When it instead receives an instance https://github.com/remiprev/her/blob/master/lib/her/model/associations/has_many_association.rb#L88
attempts to iterate over the instance and raises an exception.

This patch ensures that we always operate on a collection and allows delegated methods to work even when the response from the get request is blank. e.g. fixes #187

# the response is nil.
unless collection.is_a?(Her::Collection)
for_collection = collection.attributes.empty? ? [] : collection
collection = Her::Collection.new(Array(for_collection))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better if this'd be done when calling super?

…fetch that the response should be a collection, instead of turning the response into a collection.
* master:
  Fix data cache on model for associations, fixes remi#248
  Update README.md

Conflicts:
	lib/her/model/associations/association.rb
	spec/model/associations_spec.rb
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.

blank? returns false for a nested resource that is null
2 participants