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

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.
6b7c871c2036a41f0253580074b406cc?d=identicon&s=25 Nick C. (n1c)
on 2005-12-01 22:46
I have two Models:

Company
belongs_to :company_type

CompanyType
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.