I use dependent destroy all the time but in this one case it is not enough.
In my side model I want to be able to delete both the conversation and the
"other side" of the conversation... problem is I am getting the
following
error:
uninitialized constant Side::Conversation
I can''t seem to understand why I am getting that error. Would great
appreciate some feedback! :-) Code is below!
class Side < ActiveRecord::Base
before_destroy :delete_conversation_and_other_side
belongs_to :conversation
belongs_to :user
belongs_to :with_user, :class_name => "User", :foreign_key =>
"with_user_id"
has_many :messages, :dependent => :destroy
protected
def delete_conversation_and_other_side
Side.destroy_all("with_user_id = #{self.user_id}")
Conversation.delete_all("id = #{self.conversation_id}")
end
end
--
John Kopanas
john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org
Blog: http://www.kopanas.com
Conference: http://www.cusec.net
Twits: http://www.twitter.com/kopanas
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
thatcher.craig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-16 16:19 UTC
Re: Calling One Model From Another Model...
You should be able to get rid of the error by using self instead of
Side. ie.
def delete_conversation_and_other_side
self.destroy_all("with_user_id = #{self.user_id}")
Conversation.delete_all("id = #{self.conversation_id}")
end
On Feb 15, 11:02 pm, "John Kopanas"
<kopa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I use dependent destroy all the time but in this one case it is not enough.
> In my side model I want to be able to delete both the conversation and the
> "other side" of the conversation... problem is I am getting the
following
> error:
>
> uninitialized constant Side::Conversation
>
> I can''t seem to understand why I am getting that error. Would
great
> appreciate some feedback! :-) Code is below!
>
> class Side < ActiveRecord::Base
> before_destroy :delete_conversation_and_other_side
>
> belongs_to :conversation
> belongs_to :user
> belongs_to :with_user, :class_name => "User", :foreign_key
=>
> "with_user_id"
> has_many :messages, :dependent => :destroy
>
> protected
>
> def delete_conversation_and_other_side
> Side.destroy_all("with_user_id = #{self.user_id}")
> Conversation.delete_all("id = #{self.conversation_id}")
> end
>
> end
>
> --
> John Kopanas
> j...-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org
>
> Blog:http://www.kopanas.com
> Conference:http://www.cusec.net
> Twits:http://www.twitter.com/kopanas
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---