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

Asked

Viewed 53 times

3

Suppose I have a Real Estate 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 relationship N:N between Real Estate and Images.

If I want a property, in addition to the images, to have a cover image, what is the most correct way for me to create this field?

1 answer

2


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

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

  • Thank you, Leandro, I will use the second approach. I had also considered this possibility, but I wanted to know the opinion of those who know more than I, something different would come up. Anyway, helped or gave more confidence.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.