Forum: Ruby on Rails checking Join data for nil before accessing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2a84ec1a0c6e96a8d80bd9f569c80322?d=identicon&s=25 Justin Kay (jkay)
on 2006-01-11 18:00
So I have a join 1:0..1.  If there is nothing in the child side I get an
error when I say property.pdf.name  that I can't access nil.name.  But I
can't seem to figure out how to check if pdf is nil or not before I call
the .name function.  If I test for property.pdf == nil it always comes
back as nil, which it isn't.

Any ideas?
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-11 18:11
(Received via mailing list)
Justin Kay wrote:
> So I have a join 1:0..1.  If there is nothing in the child side I get an
> error when I say property.pdf.name  that I can't access nil.name.  But I
> can't seem to figure out how to check if pdf is nil or not before I call
> the .name function.  If I test for property.pdf == nil it always comes
> back as nil, which it isn't.
To check, use property.pdf.nil? rather than property.pdf == nil.  I
presume the latter doesn't work because the NoRecordException is raised
before the comparison can be made.
2a84ec1a0c6e96a8d80bd9f569c80322?d=identicon&s=25 Justin Kay (jkay)
on 2006-01-11 18:34
Alex Young wrote:
> Justin Kay wrote:
>> So I have a join 1:0..1.  If there is nothing in the child side I get an
>> error when I say property.pdf.name  that I can't access nil.name.  But I
>> can't seem to figure out how to check if pdf is nil or not before I call
>> the .name function.  If I test for property.pdf == nil it always comes
>> back as nil, which it isn't.
> To check, use property.pdf.nil? rather than property.pdf == nil.  I
> presume the latter doesn't work because the NoRecordException is raised
> before the comparison can be made.

Thanks
This topic is locked and can not be replied to.