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

blank? returns false for a nested resource that is null #187

Open
d-imal opened this issue Oct 22, 2013 · 2 comments · May be fixed by #264
Open

blank? returns false for a nested resource that is null #187

d-imal opened this issue Oct 22, 2013 · 2 comments · May be fixed by #264

Comments

@d-imal
Copy link

d-imal commented Oct 22, 2013

I'm just getting started with her, so let me know if I'm simply doing it wrong.
When a nested resource is null, I'd expect blank? to return true but it returns false.

Here's a stripped down version of my code and the resource:

class Thing
  include Her::Model

  has_one :photo
end

class Photo
  include Her::Model
end

...

[
    
{
        id: 1,
        name: "Something",
        photo: null
    },
    {
        id: 2,
        name: "Something else",
        photo: {
            id: 101,
            url: "http://example.com/image.png"
        }
    }
]

...

things = Thing.all()
things[1].photo.url # =>  "http://example.com/image.png"
things[0].photo.blank? # => false
things[0].photo.url # => NoMethodError: undefined method `empty?' for nil:NilClass

Is this a bug or do I have my models set up incorrectly? Thanks.

@vic
Copy link
Contributor

vic commented Nov 10, 2013

You can use photo? to test if the object is present.

@mculp
Copy link

mculp commented Apr 2, 2014

This same issue got me today. Is this intended functionality, or a bug? This behavior is different from the default rails behavior.

@dturnerTS dturnerTS linked a pull request Jul 2, 2014 that will close this issue
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 a pull request may close this issue.

3 participants