问题:
Well here's my problem I have three tables;嗯,这是我的问题,我有三张桌子; regions, countries, states.地区、国家、州。 Countries can be inside of regions, states can be inside of regions.国家可以在区域内,国家可以在区域内。 Regions are the top of the food chain.区域是食物链的顶端。
Now I'm adding a popular_areas table with two columns;现在我要添加一个包含两列的流行区域表; region_id and popular_place_id. region_id 和popular_place_id。 Is it possible to make popular_place_id be a foreign key to either countries OR states.是否有可能使popular_place_id 成为国家或州的外键。 I'm probably going to have to add a popular_place_type column to determine whether the id is describing a country or state either way.我可能不得不添加一个popular_place_type 列来确定id 是在描述一个国家还是州。
解决方案:
参考一: https://en.stackoom.com/question/1qiv参考二: https://stackoom.com/question/1qiv