How to reference one field to two tables?
In my tables field location.location_id must be referenced to city.id and country.id
In table location I have location_type field, for determine which parent table must be used.
CREATE TABLE `location` (
`id` mediumint UNSIGNED NOT NULL AUTO_INCREMENT,
`location_id` mediumint UNSIGNED NOT NULL,
`location_type` enum('city','country') NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `city` (
`id` mediumint UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `country` (
`id` mediumint UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
);
Is there any model for this reference, may be I need special referencing tables?