Bruno,
Thanks for the reply. Your suggestion has turned out to be quite
challenging to implement, at least for me. I tried adding app/models/
user_observer.rb:
class UserObserver < ActiveRecord::Observer
def before_destroy(user)
user.comments_as_author.each do |comment|
if comment.commentable_type == 'Program'
comment.reload
comment.update_attributes(:user_id => nil)
end
end
end
end
But get the error:
Couldn't find Comment with ID=#####
Yet the referenced Comment (#####) is in fact present in the database.
I think there's some interaction with optimistic record locking that
is preventing me from seeing the child comment records that I'm
targeting.
Any ideas? Thanks,
Steve
On Sep 17, 1:49 pm, Bruno Bornsztein <[email protected]>
wrote:
> Hi Steve,
> Unfortunately it's not that easy to override the association (because it's a
> macro, and Desert doesn't handle mixing those in).
>
> > I created app/models/user.rb to override specific things from the core
> > CE user.rb model. Here is my simple app/models/user.rb:
>
> > class User < ActiveRecord::Base
>
> > has_many :comments_as_author, :class_name => "Comment", :foreign_key
> > => "user_id", :order => "created_at desc", :dependent => :nullify
>
> > end
>
> Exactly. This is what you'd expect. But since the 'has_many' is not a class
> or instance method, but a macro, Desert doesn't override it.
>
> I'm not exactly sure how to get around this; I think you might have to dig
> into the ActiveRecord callback chain and override where the associated
> comments are destroyed.
>
> Anybody have other ideas?
>
> Thanks,
> Bruno
>
> The only difference between the two is the :dependent action. As you
>
>
>
> > can see, I'm trying to override ":destroy" with ":nullify". But this
> > doesn't work: When I delete a user, all the user's comments are
> > deleted as well.
>
> > Please, any help is appreciated. Thanks,
> > Steve
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "CommunityEngine" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<communityengine%2Bunsubscribe@
> > googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/communityengine?hl=en.
--
You received this message because you are subscribed to the Google Groups
"CommunityEngine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/communityengine?hl=en.