Я знаю, что варианты этого вопроса задавались много раз до (и я их читал, два из них: 1 , 2 ) , но я просто не могу осмыслить то, что кажется правильным решением.
Было предложено все: от многих ко многим отношениям, до разветвления, до полиморфных ассоциаций, до решений NoSQL, до очередей сообщений , денормализации и их комбинаций.
Я знаю, что этот вопрос очень ситуативный, поэтому я кратко объясню свой:
For the mean time, I ended up going with a denormalized setup basically being made up of an events table consisting of: id
, date
, user_id
, action
, root_id
, object_id
, object
, data
.
user_id
being the person that triggered the event.action
being the action.root_id
being the user the object
belongs to.object
being the object type.data
containing the minimum amount of information needed to render the event in a user's stream.
Then to get the desired events, I just grab all rows in which the user_id
is the id of a user being followed by whose stream we're grabbing.
It works, but the denormalization just feels wrong. Polymorphic associations seem similarly so. Fanout seems to be somewhere in between, but feels very messy.
With all my searching on the issue, and reading the numerous questions here on SO, I just can't get anything to click and feel like the right solution.
Any experience, insight, or help anyone can offer is greatly appreciated. Thanks.