Frank Kim
2006-Jan-21 03:40 UTC
[Rails] need some help designing my threaded messaging system
Hi, I want to create a messaging system that recognizes threads of messages, not unlike gmail. So far I have these models: Conversation belongs_to :user has_many :messages Message belongs_to :conversation The problem I am running into is not only does a conversation belong to a user but the conversation also has a receipient user with his/her corresponding conversation. How would I model that? Thanks, Frank -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060121/e1f92fef/attachment.html
Adam Denenberg
2006-Jan-21 03:56 UTC
[Rails] need some help designing my threaded messaging system
well i think the message would have the recipient/sender not the conversation. the conversation is a one to many of conversation -> messages. i think you need to decide one way or the other if the messages have many users that are recipients or has_many users that are senders. I dont think you can have both. Although you could have two fields in the messages table that hold user_id , and do separate left joins on them. 1 to get the sender and one to get the recipient. so in your messages table there would be a user_id field which would be the sender of the message. You would also put a recipient_id field , which would be a user_id as well , however this would hold the recipient. sender ----------------- select * from messages left join users on messages.user_id = users.id recipient ------------------- select * from messages left join users on messages.recipient_id = users.id make sense ? adam On 1/20/06, Frank Kim <railsonly@gmail.com> wrote:> Hi, > > I want to create a messaging system that recognizes threads of messages, not > unlike gmail. > > So far I have these models: > > Conversation > belongs_to :user > has_many :messages > > Message > belongs_to :conversation > > The problem I am running into is not only does a conversation belong to a > user but the conversation also has a receipient user with his/her > corresponding conversation. How would I model that? > > Thanks, > Frank > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Frank Kim
2006-Jan-22 01:12 UTC
[Rails] need some help designing my threaded messaging system
I don''t understand why you would have the recipient/sender in the message. It should be in the conversation because a conversation occurs between two people so why redundantly have that information in the messages? I think it makes more sense that each party in the conversation has his own concept of the conversation with his own messages. That is, User A has Conversation A with User B''s Conversation B. However I''m stuck on how to represent that in a rails model. Would it be? Conversation belongs_to :user has_many :messages has_one: recipient_conversation belongs_to: sender_conversation On 1/20/06, Adam Denenberg <straightflush@gmail.com> wrote:> > well i think the message would have the recipient/sender not the > conversation. the conversation is a one to many of conversation -> > messages. > > i think you need to decide one way or the other if the messages have > many users that are recipients or has_many users that are senders. I > dont think you can have both. Although you could have two fields in > the messages table that hold user_id , and do separate left joins on > them. 1 to get the sender and one to get the recipient. > > so in your messages table there would be a user_id field which would > be the sender of the message. You would also put a recipient_id field > , which would be a user_id as well , however this would hold the > recipient. > > sender > ----------------- > select * from messages left join users on messages.user_id = users.id > > recipient > ------------------- > select * from messages left join users on messages.recipient_id = users.id > > make sense ? > > adam > > On 1/20/06, Frank Kim <railsonly@gmail.com> wrote: > > Hi, > > > > I want to create a messaging system that recognizes threads of messages, > not > > unlike gmail. > > > > So far I have these models: > > > > Conversation > > belongs_to :user > > has_many :messages > > > > Message > > belongs_to :conversation > > > > The problem I am running into is not only does a conversation belong to > a > > user but the conversation also has a receipient user with his/her > > corresponding conversation. How would I model that? > > > > Thanks, > > Frank > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Frank Kim http://betweengo.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060122/b576b81c/attachment.html
iStormy
2006-Jan-24 04:45 UTC
[Rails] Re: need some help designing my threaded messaging system
Frank Kim wrote:> I don''t understand why you would have the recipient/sender in the > message. It should be in the conversation because a conversation occurs > between two peopleI have email discussions with more than one person, and so do many other people. If you assume otherwise, you''ll just have to go back and rewrite your database and code to fix it when other people start using your program--because they''ll complain to no end that you only allowed for 2 people in a thread. (c: -- Posted via http://www.ruby-forum.com/.