3 ms·
Whoa, cool feature I hadn't heard about. Good to know! Another approach to this problem I've used in the past is Postgres views, which basically let you create
by corwinstephen 6y ago
Whoa, cool feature I hadn't heard about. Good to know!
Another approach to this problem I've used in the past is Postgres views, which basically let you create a third table that's either materialized (constructed in advance) or generated on the fly and has columns based on transforms of the first two tables. So in this case you could create a Post model backed by a view table that pulls in the names and other metadata it needs from the text and video tables and merges them into columns that function as a third table in the eyes of the Post model. But there's no actual duplication / denormalization happening, which keeps things clean..
- correlator 6y agoThat is an interesting approach. Our of curiosity, how is an engineer made aware of the psql view? For example, the view likely relies on specific columns in specific models. What guard rails are available for preventing this kind of breaking change with the view approach?
- corwinstephen 6y agospecs--it's basically the same question as with changing the structure of any db table. How do you know some code doesn't rely on it? We also use/love this gem https://github.com/scenic-views/scenic https://github.com/scenic-views/scenic to version our views