Messaging - the best way to implement?

I’m developing a messaging service for an application. It’s not an
instant messaging, it’s more similar to how e-mail works. I send a
message to user, user receives the message, I have a copy of the
message sent by me in ‘sent’ folder.

That’s what the question is about. User gets the message from me and I
have a copy of that message in ‘sent’ folder. Where to store both of
them? Do I need different tables within database - one for messages
and another one for sent messages? Or it could be working well with
one table? Do I really need to make a copy of message in order to make
a sent message? Or it could be done without data redundancy, i.e. with
one entry in one table per message?

That’s not the question particularly about rails, but I’m not aware
where to ask. Someone should have done something similar. Any advices?

Thanks.

I’d define it like this:

User model
has_many :from_messages. :class_name => “Message”, :foreign_key =>
“from_id”
has_many :to_messages, :class_name => “Message”, :foreign_key => “to_id”

Message model:
belongs_to :to, :class_name => “User”, :foreign_key => “user_id”
belongs_to :from, :class_name => “User”, :foreign_key => “user_id”

I think in Rails 2.0 you don’t need to specify the foreign keys for the
belongs_to on messages because it’ll guess it from the class name.

On Jan 11, 2008 9:50 AM, truetype [email protected] wrote:

one table? Do I really need to make a copy of message in order to make
a sent message? Or it could be done without data redundancy, i.e. with
one entry in one table per message?

That’s not the question particularly about rails, but I’m not aware
where to ask. Someone should have done something similar. Any advices?

Thanks.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Also, to save you a lot of time. There are some GREAT messaging
plugin’s that handle all the basic work and features up on the
agilewebdevelopment site.

http://agilewebdevelopment.com/plugins/search?search=messaging

acts_as_messagable sounds like it’ll do what you want and more.
Restful_easy_messages sounds good too.