vimal
2009-Mar-09 12:33 UTC
Protecting an associated record from destroying -- How To and explanation?
Hi, I have a model "Pattern" with subject and body as columns and another "Schedule" with date, time and pattern_id(for inserting an association to Pattern table) I had defined it as --------------------------------------------------------------------------------------- class Schedule < ActiveRecord::Base has_one :pattern end --------------------------------------------------------------------------------------- class Pattern < ActiveRecord::Base belongs_to :schedule end --------------------------------------------------------------------------------------- So whenever you need to create a schedule u need to a pattern also. Then i removed the pattern which was used by a schedule. How can i avoid this action. I wonder then whats the reason of having these relationships Is there any additional things reqd. for me to do Regards, Vimal Das --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ar Chron
2009-Mar-09 13:27 UTC
Re: Protecting an associated record from destroying -- How To and explanation?
vimal wrote:> Then i removed the pattern which was used by a schedule. > How can i avoid this action. >As the old family physician used to say, "If it hurts, don''t do it." If you want to protect against pattern deletion, you could just eliminate the destroy method from the Pattern controller, and make the Pattern destroy happen only through the "parent" Schedule destroy. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harold A. Giménez Ch.
2009-Mar-09 13:34 UTC
Re: Protecting an associated record from destroying -- How To and explanation?
Another option is using the before_destroy callback to do the check: http://apidock.com/rails/ActiveRecord/Callbacks/before_destroy On Mon, Mar 9, 2009 at 9:27 AM, Ar Chron <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > vimal wrote: > > Then i removed the pattern which was used by a schedule. > > How can i avoid this action. > > > > As the old family physician used to say, "If it hurts, don''t do it." > > If you want to protect against pattern deletion, you could just > eliminate the destroy method from the Pattern controller, and make the > Pattern destroy happen only through the "parent" Schedule destroy. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---