I'm trying to understand how best to make a notification scheme for multiple actions and nodes. Basically you should notify someone whenever a message or tan action is performed.
Message: Fulano de tal enviou uma mensagem
Enjoyed: Fulano de tal curtiu seu texto [prévia com texto]
The problem is to relate all this, because a precise case of the user name and otherwise relate to retrieve the text and the link.
select
case tipo
when 'mensagem' then ( [...] )
when 'curtiu' then ( select concat( nome , '//' , acao , '//' , body ) from tabela
inner join [...] where [...] )
end 'data'
from notificacao
As line-line, I thought of doing a simple select with subquery in each case depending on the type of the notification, use concat
and explode
to break the elements. The above query would return rows as Papa Cahrlie//curtiu//Lorem ipsum...
.
In this scheme each type would have a subquery, but I have more 'events' besides the example, and I will have more complex querys. You could even use views
if that's the case.
TABLE:
CREATE TABLE 'notificacao' (
'ID' int(11) NOT NULL AUTO_INCREMENT,
'USUARIO' int(11) DEFAULT NULL,
'CONTEUDO' int(11) DEFAULT NULL,
'TIPO' enum( '...' ),
'STATUS' enum( '0' , '1' ) DEFAULT '0',
)
My table is simple - generic -, which records the user, the type of event, and the reference of the content that underwent the action. I wanted opinions on working with this select more simply and / or efficiently.