Child record becomes orphan

Hi all,

I’ve got these company (has) contacts relational tables. I want to make
sure a
company can’t be deleted when it still has contacts. (because I can now,
which results in nil like errors when listing the contacts …

Are there any helpers to do so, is Rails aware of this? Or do I need to
put in
a condition before destroying the company record in question myself?

def destroy_company

Haven’t figured out the syntax yet so don’t laugh about the line

if Contact.find_all(params[:company_id]) == Company.find(params[:id])
flash[:notice] = ‘This company has contacts.’
redirect_to :action => ‘show_company’, :id =>
redirect_to :action => ‘list_companies’

Thanx Regards,


“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”

My $Grtz =~ Gerard;

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs