I am curious as to how I should organize image storage in my application. They will be stored on disk somewhere, with the path / url stored in the database, but my application has become complex and image organization is leaving me baffled. The technology I am using is ASP.NET MVC 3 + EF 4.1 Code First (which is proving to be difficult with complex relationships).
This is a family based application, so there is a Family table, Member table, and a FamilyMember table to link to two. There is also a FamilyEvent, and MemberEvent table to track events in the family or member’s life.
Use cases
A Member can upload multiple profile pictures (possibly to be put in a “profile” album?)
A Member can upload “family” photos, to be attached to the Family object, and put into some type of album for the family.
A Member can add a member event, and attach multiple images to the members event.
A Member can add a family event, and attach multiple images to the family’s event.
These are the base use cases.
My thoughts
Base “Picture” table with id, description, and maybe the user id of the uploader.
MemberProfilePicture table with id, pictureId, memberId, etc…
MemberEventPicture table with id, pictureId, [member id?], membereventid, etc…
FamilyEventPicture table with id, pictureId, [familyId ?], familyeventid, etc…
This would allow a family or member to essentially “link” a Picture later to another profile pic / member event / or family event.
My question
Is this correct, or am I over-complicating this? I don’t see any other way other than multiple tables to represent images for different things, which all refer to the base Picture table. Can anyone give any suggestions as to how I can improve this model? While I understand there may be many definitions to correct, I’m looking for solutions as far as how to organize the imaging aspect of my application, or improvements on what I have already.
What I would do is have three tables.
The ‘picture’ table which stores a unique id for each picture and the location.
The ‘profile’ table which has your dtails about the profile.
A third ‘linking’ table composed of pictureId and profileId
If I want to link picture A to profile X I just add in “A,X” to the linking table. Same thing for events or whatever. If there’s going to be a many-to-many relationship this is the cleanest way to go (I’m assuming that the same picture can be in multiple profiles).
Hope I understood your problem correctly.