Looking for some help here.
I have 4 models
Image, Section, Page, Post
An image can belong to only one of the Section,Page or Post.
A Post could have multiple images.
First though was save a foreign_key id in the Image table however this wont work as a post can have an Id of 1 as can a Page
Second go was with help from people was to create a linktable with a look up
Tags
Section = 1
Page = 2
Post =3
Image = 4
___
ItemLookup
|id|parent_id|parent_tag|child_id|child_tag|
This way we can then add things at a later date live videos etc.
However have been told this is wrong.
New though is in the Image table add an parent_id and parent_type id fields. This is the only other solution I can see at the moment.
Thoughts?
Thanks
I have 4 models
Image, Section, Page, Post
An image can belong to only one of the Section,Page or Post.
A Post could have multiple images.
First though was save a foreign_key id in the Image table however this wont work as a post can have an Id of 1 as can a Page
Second go was with help from people was to create a linktable with a look up
Tags
Section = 1
Page = 2
Post =3
Image = 4
___
ItemLookup
|id|parent_id|parent_tag|child_id|child_tag|
This way we can then add things at a later date live videos etc.
However have been told this is wrong.
New though is in the Image table add an parent_id and parent_type id fields. This is the only other solution I can see at the moment.
Thoughts?
Thanks
Last edited: