# NULL id's / invalid references

**URL:** <https://www.ruby-forum.com/t/null-ids-invalid-references/96829>\
**Category:** Rails\
**Created:** [January 24, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/null-ids-invalid-references/96829 "2006-01-24T22:06:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcinJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@MarcinJ](https://www.ruby-forum.com/u/MarcinJ)\
**Post date:** [January 24, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/null-ids-invalid-references/96829/1 "2006-01-24T22:06:35Z")

</div>

Hi,

could you suggest me how to handle this in a proper way? I have a table  
which has  
othertable\_id column (relationship is belongs\_to) Problem is, that  
sometimes there is a NULL value and table.othertable.foo returns an  
error… what should I do about it? change something in model? in view?  
or just add “unknown” row to othertable and update table.othertable\_id  
with id of this row?

tia, m.

---

<div class="post-metadata">

**Author:** ![MarcinJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@MarcinJ](https://www.ruby-forum.com/u/MarcinJ)\
**Post date:** [January 24, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/null-ids-invalid-references/96829/2 "2006-01-24T22:20:29Z")

</div>

Sounds like a case of missing lookup/reference values.

have a look at the act as enumeration plugin by Trevor S…

[http://wiki.rubyonrails.org/rails/pages/Acts+As+Enumerated+Plugin](http://wiki.rubyonrails.org/rails/pages/Acts+As+Enumerated+Plugin)

It allow you to build your own handler for each senario…  
:on\_lookup\_failure

def your\_lookup\_handler(operation, name,  
name\_foreign\_key,  
acts\_enumerated\_class\_name, lookup\_value)  
end

you may then choose to have a default values, or an raise an exception  
whatever…

regards,

---

<div class="post-metadata">

**Author:** ![MarcinJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@MarcinJ](https://www.ruby-forum.com/u/MarcinJ)\
**Post date:** [January 24, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/null-ids-invalid-references/96829/3 "2006-01-24T22:37:55Z")

</div>

Leon L. wrote:

> you may then choose to have a default values, or an raise an exception  
> whatever…

Thanks a lot, I’ll check it!

m.
