Forum: Ruby on Rails NULL id's / invalid references

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.
08a88639ee299bb626afdc1dc8e459c7?d=identicon&s=25 MarcinJ (Guest)
on 2006-01-24 22:06
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.
2073c7e0e7d2311727b680a887a375be?d=identicon&s=25 Leon Leslie (Guest)
on 2006-01-24 22:20
(Received via mailing list)
Sounds like a case of missing lookup/reference values.

have a look at the act as enumeration plugin by Trevor Squires..

http://wiki.rubyonrails.org/rails/pages/Acts+As+En...


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,
08a88639ee299bb626afdc1dc8e459c7?d=identicon&s=25 MarcinJ (Guest)
on 2006-01-24 22:37
Leon Leslie wrote:

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

Thanks a lot, I'll check it!

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