Forum: Ruby on Rails :dependent => nullify results in nil object error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Nick C. (Guest)
on 2005-12-01 23:46
I have two Models:

belongs_to :company_type

set_table_name "company_type"
has_many :companies, :dependent => :nullify

The company table has fields: id, company_type_id, etc...
The company_type table has fields: id, ctype

When I delete a CompanyType, the nullify dependency sets the
company_type_id to 0 in the Company table, which results in a nil object
error in /company/list

Can anyone suggest a workaround for this? I am thinking of adding a
rescue in the list method which asks the user to reassign the ctype if
it is null, but am wondering if there's a better way?
This topic is locked and can not be replied to.