(SQL) Each property has several images and a cover image

3

Suppose I have a Property table where a property can have multiple images.

I have, therefore, another table, Images, with the url.

I also have an intermediate table that makes the N: N relationship between Real Estate and Images.

If I want a property other than the images to have a cover image, what is the best way for me to create this field?

    
asked by anonymous 15.12.2017 / 15:27

1 answer

2

You can add a "Cover" column in your Images table, of a Boolean type. This way you can indicate that this is the cover image, including more than one if you are going to make a slide show. In your application you define the rule for when to display the cover image or not.

Another approach is to add a column in your Property table which will be an FK for the Image table indicating which of the images will be the cover page. But leave this constraint as nullable. Otherwise you would have to have the images registered before you even created the initial registration for the property.

    
15.12.2017 / 15:32