4

I'm not good with diagramming tools or ascii art, so here's a hand-drawn diagram of what I have:

badly drawn diagram

In short, I have what can loosely be described as a scavenger hunt app. A game has several objectives, and players can attempt the objective, comment on the objective, share hints, share images, etc. Each of these actions have different schemas (An attempt has a verification_flag, a comment has comment_text, an image has an image_url, etc).

In my app, on the "Objective" dashboard, I want to show an activity feed for that objective. How can I best do this?

For the schemas described in the badly drawn diagram, I was thinking something like this:

SELECT * FROM activities
LEFT OUTER JOIN images on images.activity_id = activities.activity_id
LEFT OUTER JOIN comments on comments.activity_id = activities.activity_id
LEFT OUTER JOIN links on links.activity_id = activities.activity_id
LEFT OUTER JOIN attempts on attempts.activity_id = activities.activity_id
LEFT OUTER JOIN hints on hints.activity_id = activities.activity_id
WHERE activities.objective_id = 123
ORDER BY activities.created_at DESC

...and when the app receives the results of this monstrosity, it will somehow go row by row, figure out which class the row represents (oh, this row, is it an Image, Comment, Attempt, Hint, etc?) then render the appropriate template for the browser.

I've read about the "exclusive arc" pattern and that it should be avoided, but it is unclear how to avoid it. So for this problem, can I please get some specific guidelines or pointers in how to do this correctly?

Community
  • 1
  • 1
000
  • 26,951
  • 10
  • 71
  • 101
  • 1
    Exclusive arc is (as far as I know the term used) when you have multiple foreign keys in a single entity, and only one (or a restricted subset) of them can be non null at any one time. I can't see that problem in your diagram. – Joachim Isaksson Sep 28 '14 at 06:23
  • 1
    The answer you cite in support of avoiding exclusive arcs doesn't really say that. It's saying to avoid one particular implementation of an exclusive arc--an implementation that's obvious (and suboptimal) to an application programmer. [Here's one alternative implementation.](http://stackoverflow.com/a/4970646/562459) – Mike Sherrill 'Cat Recall' Sep 28 '14 at 13:53

0 Answers0