Good, I have a table products and I want each product to have one or several images. so create a table images with a foreign key to products.
something like this:
create table producto(
id_producto serial,
nombre character varying(20),
....
);
create table imagen(
id_imagen serial,
id_producto integer,
nombre character varying(100),
foreign key(id_producto) references producto(id_producto)
...
);
So far I think I'm doing fine, the problem is that I want that at the moment of creating a product, it has a main image (ideally that can be ordered), but if I put a field as principal boolean
in the table of images and then someone adds an image and defines it as main, I will have 2 main images, so I may double my records by making a query that calls only the main one.
I do not know if I explain myself well, but I do not see how to be clearer.
The only thing that occurs to me is to validate this in the form, but I would like to know if I have any other option.
I would also like the images to be sorted. with a field posicion integer
or something like that.
How do pages work like mercadolibre in this sense?