# Dealing with nil relation

**URL:** <https://www.ruby-forum.com/t/dealing-with-nil-relation/148400>\
**Category:** Rails\
**Created:** [September 12, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/dealing-with-nil-relation/148400 "2008-09-12T14:54:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 12, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/dealing-with-nil-relation/148400/1 "2008-09-12T14:54:31Z")

</div>

I have a person table and a relation to a table for absents. When  
listing absents I get the name by the relationship and the person\_id.  
But now I get an error because the person is deleted. How do I check if  
a relation is missing?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 12, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/dealing-with-nil-relation/148400/2 "2008-09-12T15:14:04Z")

</div>

you can check for nil of course…

eg:  
\<%= @absent.person.name if @absent.person %\>

But that is weak db/model design.

-Either don’t allow deletion of persons and use an is\_active flag  
instead,  
(most likely the best way to handle this)

- or make sure that if you delete a person all related records get  
deleted too.  
You can do this manually in the destroy action of the  
PersonsController  
or by using :dependent =\> destroy for all the associations.
