# Workaround when associated object is null

**URL:** <https://www.ruby-forum.com/t/workaround-when-associated-object-is-null/147046>\
**Category:** Rails\
**Created:** [August 27, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/workaround-when-associated-object-is-null/147046 "2008-08-27T23:37:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@Glen](https://www.ruby-forum.com/u/Glen)\
**Post date:** [August 27, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/workaround-when-associated-object-is-null/147046/1 "2008-08-27T23:37:07Z")

</div>

Hi,

I am trying to generate CSV like blow.

```
students = Student.find(:all, :include =>

```

[:application, :person], :conditions =\> conditions)

```
csv_string = FasterCSV.generate do |csv|
  csv << %w["student_status", "semester", "id_number",

```

“last\_name”, “first\_name”]  
students.each do |c|  
csv \<\< [c.status, c.application.semester\_desc,  
c.person.id\_number, c.person.last\_name, c.person.first\_name]  
end

If the student does not have a record of application or person. Rails  
complains about null association.  
I can create conditional statement e.g., “if c,application” to  
workaround null, but there are lots of fields in my real code do not  
want to waste my time for putting if statement.

Are there any way so that I can just insert null or empty string when  
association is null?

Thanks in advance.

Glen
