Reputation: 25373
I'm trying to design a data model for my current project, and I'm having trouble. The product owner wants to have Users, Searches, Documents, and Tags. Here's what seems to be well known thus far:
There are two issues I'm trying to manage here:
One thing that's possibly confounding my understanding here is that I'm thinking through the Ruby on Rails ActiveRecord ORM. I will eventually have to implement whatever solution I find within Rails.
Upvotes: 1
Views: 60
Reputation: 115630
One possible design:
User
1| \1
| \
\ N\
\ Search Document
\ \1 1/ /1
\ \ / /
\ N\ /M /
\ Search-Returns-Document /
\ /
\ /
\N M/
User--Views--Document Tag
1\ 1/
\ /
\N /M
User-Marks-Document-With-Tag
Upvotes: 2
Reputation: 3550
Hopefully this will help:
Have a Documents_Viewed table that contains the user_id, document_id, etc.. then when retrieving the search result join the viewed table on user and document which will let you know if they have read it.
I would have another table Document_Tags that contain user_id, document_id, tag since you mentioned tags are user dependant
And example theoretical query would be:
SELECT * FROM Docuemnts d
LEFT JOIN Document_Viewed dv ON (dv.document_id = d.id AND dv.user_id= ?)
LEFT JOIN Document_Tags dt ON (dv.document_id = d.id AND dv.user_id= ?)
WHERE (search_criteria)
Not sure if that helps you at all
Upvotes: 0