Delegated Types in Rails, handling models with overlapping attributes
blackboxengineering.work
Delegated Types in Rails, handling models with overlapping attributes
1–4 of 4 posts
Re: Delegated Types in Rails, handling models with overlapping attributes
#2Another 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..
Re: Delegated Types in Rails, handling models with overlapping attributes
#3Whoa, 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 metada…
Re: Delegated Types in Rails, handling models with overlapping attributes
#4Whoa, 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 metada…
That 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?
We also use/love this gem https://github.com/scenic-views/scenic to version our views