# Checking Join data for nil before accessing

**URL:** <https://www.ruby-forum.com/t/checking-join-data-for-nil-before-accessing/61020>\
**Category:** Rails\
**Created:** [January 11, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/checking-join-data-for-nil-before-accessing/61020 "2006-01-11T18:00:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [January 11, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/checking-join-data-for-nil-before-accessing/61020/1 "2006-01-11T18:00:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [January 11, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/checking-join-data-for-nil-before-accessing/61020/2 "2006-01-11T18:11:36Z")

</div>

Justin K. 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.

---

<div class="post-metadata">

**Author:** ![jkay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@jkay](https://www.ruby-forum.com/u/jkay)\
**Post date:** [January 11, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/checking-join-data-for-nil-before-accessing/61020/3 "2006-01-11T18:34:18Z")

</div>

Alex Y. wrote:

> Justin K. 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
