Pete Yandell
2007-Jul-29 09:46 UTC
Fix to make has_one/has_many :dependent behaviour consistent (my first patch)
I''ve just submitted my first patch, and I''d love to get some feedback on it. This patching Rails thing is a bit daunting if you haven''t done it before! Not sure if I''m on the right track. http://dev.rubyonrails.org/ticket/9129>From the description:A has_one or has_many relationship with :dependent set either :nullify will incorrectly destroy the associated objects when the association is reassigned or set to nil. Instead, the associated objects'' foreign keys should be nullified, as they are when the parent object is destroyed. For example, given this association: class Fred has_one :george, :dependent => :nullify end The following will cause george to be destroyed. fred = Fred.create george = George.create(:fred_id => fred) fred.george = nil The issue also extends to :dependent => :delete and :dependent => :delete_all. Associated objects are destroyed rather than deleted when the association is reassigned. The attached patch fixes this issue and makes :dependent behaviour consistent in all circumstances the I can think of. Cheers, Pete Yandell http://notahat.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Pete Yandell
2007-Jul-29 09:53 UTC
Re: Fix to make has_one/has_many :dependent behaviour consistent (my first patch)
D''oh! And I just realised I made a typo in the first line of the description. It should read: A has_one or has_many relationship with :dependent set to :nullify... It''s been a long day. Pete Yandell http://notahat.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Mear
2007-Jul-30 12:37 UTC
Re: Fix to make has_one/has_many :dependent behaviour consistent (my first patch)
Hey Pete, Looks like a good patch, but I think they''re already discussing the issue here: http://dev.rubyonrails.org/ticket/7309 It certainly seems to cover some of the same ground (must admit I haven''t looked into it in too much detail). Maybe check that ticket out and see if there''s anything to add to it from your patch? Cheers, Chris On Jul 29, 10:46 am, Pete Yandell <p...@notahat.com> wrote:> I''ve just submitted my first patch, and I''d love to get some feedback > on it. This patching Rails thing is a bit daunting if you haven''t done > it before! Not sure if I''m on the right track. > > http://dev.rubyonrails.org/ticket/9129 > > >From the description: > > A has_one or has_many relationship with :dependent set either :nullify > will incorrectly destroy the associated objects when the association > is reassigned or set to nil. Instead, the associated objects'' foreign > keys should be nullified, as they are when the parent object is > destroyed. > > For example, given this association: > > class Fred > has_one :george, :dependent => :nullify > end > > The following will cause george to be destroyed. > > fred = Fred.create > george = George.create(:fred_id => fred) > > fred.george = nil > > The issue also extends to :dependent => :delete and :dependent > => :delete_all. Associated objects are destroyed rather than deleted > when the association is reassigned. > > The attached patch fixes this issue and makes :dependent behaviour > consistent in all circumstances the I can think of. > > Cheers, > > Pete Yandellhttp://notahat.com/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Pete Yandell
2007-Jul-31 00:58 UTC
Re: Fix to make has_one/has_many :dependent behaviour consistent (my first patch)
On Jul 30, 10:37 pm, Chris Mear <ch...@odegy.com> wrote:> Looks like a good patch, but I think they''re already discussing the > issue here: > > http://dev.rubyonrails.org/ticket/7309Saw that, but it only addresses has_many relationships, and changes the default behaviour when :dependent isn''t set in a way that might break things. Thanks for reminding me of that though...I''ll at least add some links between the tickets. Pete Yandell http://notahat.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---