Hi, Is there a way to use the :dependent option to set a certain attribute to null rather than destroying the records? For example, take the following models: User id, integer name, string group_id, integer belongs_to :democrats Groups id, integer name, string has_many :users If I delete a certain group, is there a way to have the ''group_id'' attribute of all the users affiliated with the deleted group be set to null rather than be destroyed? Thank you! -- 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 -~----------~----~----~----~------~----~------~--~---
Ooooh, I''m so excited. I found my answer. :dependent => :nullify will do what I want. I hope this will help some person in the future. -- 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 -~----------~----~----~----~------~----~------~--~---
Now if there was just a built-in way to have something like :dependent => :deny we''d be set. By the way, what is the best way to support the "deny delete" association rule. Just to clarify this is saying "Deny deletion of the parent object if it has one or more children." This rule is often useful to ensure referential integrity. Example: Scenario 1: An admin creates a new product with item number 1010. It is realized later that the item will never be sold. Since no orders of the product exist in the system it''s fine to delete the item. Scenario 2: It is discovered that an existing product with item number 1001 is no longer available to be sold. The admin attempts to delete the existing product, but there are outstanding orders containing product 1001. It''s not good to use either :dependent => :destroy nor :dependent => :nullify in this scenario. You can''t simply let the system automatically delete all orders containing product 1001. You must first resolve the orders (child objects) before deleting the product object. Does Rails have built-in support for this common referential integrity rule? On Dec 30, 6:09 am, Rick Penn <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ooooh, I''m so excited. I found my answer. :dependent => :nullify will do > what I want. I hope this will help some person in the future. > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
No it doesn''t. You''ll need to build your own before_destroy validation method for this. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If I understood you correctly I think this plugins does what you want. http://agilewebdevelopment.com/plugins/dependent_protect_option -- Amaia Castro Dabne Tecnologías de la Información - www.dabne.net - http://blog.dabne.net ~~*~~ Buscador de Subvenciones - http://buscaboe.dabne.net ~~*~~ 2007/12/31, Robert Walker <rwalker348-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > > Now if there was just a built-in way to have something like :dependent > => :deny we''d be set. > > By the way, what is the best way to support the "deny delete" > association rule. Just to clarify this is saying "Deny deletion of the > parent object if it has one or more children." This rule is often > useful to ensure referential integrity. > > Example: > Scenario 1: An admin creates a new product with item number 1010. It > is realized later that the item will never be sold. Since no orders of > the product exist in the system it''s fine to delete the item. > > Scenario 2: It is discovered that an existing product with item number > 1001 is no longer available to be sold. The admin attempts to delete > the existing product, but there are outstanding orders containing > product 1001. It''s not good to use either :dependent => :destroy > nor :dependent => :nullify in this scenario. You can''t simply let the > system automatically delete all orders containing product 1001. You > must first resolve the orders (child objects) before deleting the > product object. > > Does Rails have built-in support for this common referential integrity > rule? > > On Dec 30, 6:09am, Rick Penn <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Ooooh, I''m so excited. I found my answer. :dependent => :nullify will do > > what I want. I hope this will help some person in the future. > > -- > > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---