I do not want to build polymorphic relationships into my db schema.
Where in the past I would have had a column called entity_id and another called entity_type.
Between the two of them, I could look up a related record. This could be from tables village, town or country
Redbean even kindly helps me achieve this, with the poly() method.
However, I understand this is an anti-pattern and I want to avoid it.
Instead, I introduce another table in between the two - let's call it place
In my parent table, I now have a single column, place_id, with a foreign key to place.
Each of the other tables has a 1:! relationship with place, via foreign-keyed place_id.
As far as I can see, this protects the integrity of my db, all foreign key columns reference a single other table.
My problem now, is how do I retrieve the village, town or country with Redbean?
Right now, I'm iterating over these three known tables and looking for an ID matching place_id. Pretty expensive and brittle way to do it though I think.
So I considered adding a qualifier into the place table, of entity_type. But then it feels like I'm back where I started, I have to use poly() again...