[Rails] Child record becomes orphan
Gerard
mailing at gp-net.nl
Sun Jan 1 21:27:39 GMT 2006
Robby,
Looked at your site and coding work. Very impressive. After having thought the
mather through. I concluded the 'recursive' removal can be very nasty as
well. If for instance you have a customer table (has) projects (has) tasks
the result can be a lot more records removed then was the intention.
Any experience on what's practical?
Thanx a lot.
regards,
Gerard.
On Sunday 01 January 2006 20:02, Robby Russell tried to type something like:
> On Sun, 2006-01-01 at 19:52 +0100, Gerard wrote:
> > 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 ...
> > obviously)
> >
> > 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
> > below. if Contact.find_all(params[:company_id]) ==
> > Company.find(params[:id]) <<< flash[:notice] = 'This company has
> > contacts.'
> > redirect_to :action => 'show_company', :id => @company.id
> > else
> > Company.find(params[:id]).destroy
> > redirect_to :action => 'list_companies'
> > end
> > end
> >
> > Thanx Regards,
> >
> > Gerard.
>
> Do you intend to force the user to delete all contacts in a company
> prior to deleting it? You can have AR destroy all the contacts when a
> company is destroyed. See this blog entry:
>
> http://rubyurl.com/bE4
>
> -Robby
--
"Who cares if it doesn't do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."
My $Grtz =~ Gerard;
~
:wq!
More information about the Rails
mailing list