The primary key is effectively 'room_hash' rather than ID, because the process that adds messages to the database only knows the room_hash, not the ID of that room. I have the feeling that's where things must get a little complicated... I tried playing with primary key stuff to no avail.
class ChatRoom < ActiveRecord::Base validates :room_hash, :uniqueness => true has_many :chat_messages, :foreign_key => :room_hash, :dependent => :destroy # damn I don't know how to pull this off outside of rails . . . end
class ChatMessage < ActiveRecord::Base belongs_to :chat_room, :foreign_key => :room_hash def decrypted_msg self.msg.tr('+/', '-_').unpack('m') end end
So when I try to delete a chat_room, it doesn't decrease the ChatMessages.count amount. What else do I need to do to complete the relationship?
This post has been edited by NotarySojac: 19 December 2012 - 06:55 PM