Hi, is the following a known issue? Given the following setup: class User < AR has_many :posts, :dependent => :destroy end class Post < AR named_scope :title_like, lambda { |title| .... [some conditions] .... end Then u = User.first u.posts # Do something that loads posts u.posts.title_like(''term'').delete_all deletes *all* posts from u - not just the ones with ''term'' in the title. This is because :dependent => :destroy makes the association enumerate the loaded target ignoring the scope. Cheers Tim
Michael Koziarski
2009-Jul-27 08:55 UTC
Re: named_scope and loaded associations with :dependent => :destroy
This is news to me, but sounds nasty and definitely a bug. Can you reproduce it in a test case in AR itself? On Monday, July 27, 2009, tim <fischbach.tim@googlemail.com> wrote:> > Hi, > > is the following a known issue? Given the following setup: > > class User < AR > has_many :posts, :dependent => :destroy > end > > class Post < AR > named_scope :title_like, lambda { |title| .... [some > conditions] .... > end > > Then > > u = User.first > u.posts # Do something that loads posts > u.posts.title_like(''term'').delete_all > > deletes *all* posts from u - not just the ones with ''term'' in the > title. This is because :dependent => :destroy makes the association > enumerate the loaded target ignoring the scope. > > Cheers > Tim > > >-- Cheers Koz