NULL id's / invalid references

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.

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

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,

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.