I want to make private messages in my site. I want that user can delete received or sent messages. For it I need two tables one for send message and one for receive....Is it to possible that when user send messages, it automatically add fro two tables? or it is better to make some relations with tables? or maybe exist better solution?
Asked
Active
Viewed 590 times
4 Answers
2
I think you need just one table:
Message:
columns:
from: integer
to: integer
header: string(100)
body: blob
show_in_outcoming:
type: boolean
default: true
show_in_incoming:
type: boolean
default: true
is_read:
type: boolean
default: false
UserFrom:
class: sfGuardUser
local: from
foreign: id
foreignType: one
type: one
UserTo:
class: sfGuardUser
local: to
foreign: id
foreignType: one
type: one
where
- is_read indicates whether or not the message been read (false - unread, true - read - for incoming messages only)
If the user who sends the message want to delete it, we simply hide it (not delete from the DB) - set show_in_outcoming to false. If the user who received the message want to delete it, we hide it too - set show_in_incoming to false. This approach allows us to recover the "hidden" messages (or remove them altogether)

melekes
- 1,880
- 2
- 24
- 30
-
Thank you! What is type field? – denys281 Jun 30 '11 at 10:36
-
Column **type** tells us whether an Message is a IncomingMessage or a OutgoingMessage. This column will be automatically added to CREATE TABLE `message` SQL query (if you are generating it) - `type VARCHAR(255)`. This is how column aggregation inheritance knows which model each record in the database belongs to. [More info](http://www.doctrine-project.org/projects/orm/1.2/docs/manual/inheritance/en#column-aggregation) – melekes Jun 30 '11 at 11:51
-
I do not very understand about Doctrine Table Inheritance(and I can not understand how it works)I have one table but three models.I want to generate module for messages, I need generate one modules for messages table?I will have one record in my DB for one message,for one user it will be out coming,for other incoming... – denys281 Jun 30 '11 at 13:01
-
I think, I understand you. I have changed my answer slightly. – melekes Jun 30 '11 at 14:06
-
Yes, this is true, but I think that there need one more column, is_readSender ,and is_readRecipiend...? – denys281 Jun 30 '11 at 14:25
-
No, you don't. Why you need a is_read field for the sender? All that he should know is whether the _recipient is read his message or not_. **is_read** field is responsible for this. Of course, you may want to add some additional fields like created_at, updated_at and so on. – melekes Jun 30 '11 at 16:48
1
Maybe, you should create a message table, with tow relation to user table:
message:
columns:
user_emitter_id: ...
user_reciever_id: ...
body: ...
relations:
userEmitter:
class: user
local: user_emitter_id
foreign: id
userReciever:
class: user
local: user_reciever_id
foreign: id

dxb
- 931
- 5
- 7
-
but when user delete for example receive message, it also will deleted for user that sent this message. – denys281 Jun 29 '11 at 13:46
-
do not delete the message... just set user_reciever_id or user_emitter to null. – dxb Jun 29 '11 at 13:54
-
hm, is it good, do not delete message from database? hm, I think I shall do this. – denys281 Jun 29 '11 at 13:56
0
Message:
columns:
from: integer
to: integer
header: string(100)
body: blob
show_in_outcoming:
type: boolean
default: true
show_in_incoming:
type: boolean
default: true
is_read:
type: boolean
default: false
relations:
UserFrom:
class: sfGuardUser
local: from
foreign: id
foreignType: one
type: one
UserTo:
class: sfGuardUser
local: to
foreign: id
foreignType: one
type: one

Krion
- 1
0
There is a symfony plugin that allows you to do this. Check sfSocialPlugin.

Pabloks
- 1,484
- 1
- 14
- 15
-
Thank you! I now, I use this plugin now, but it's not exactly what I need. Now I disabled everything except private messages there, but before sent message, you need sent "friend request" And you can not delete messages/ And there are some little conflict between sfDoctrineGuard and sfSocial...So I want to write my own simple pm ) – denys281 Jun 29 '11 at 14:13