A passionate full stack software engineer having 7 years of experience in building scalable enterprise systems. I have worked predominantly with the JVM and Javascript ecosystem but currently exploring Rails. For me, software engineering is all about solving problems in the most optimal way. I am an avid practitioner of clean code practices and love to read about System Design and Architectures. When I am not coding I love to play playstation, read anything about aviation or go out for a long drive and of-course I am foodie by heart.
1 minute read
All of us would have used aliases with SQL queries as it makes the table
and column names more readable.
The renaming is just a temporary change
and the table name does not change in the original database.
Rails now support aliased attributes with insert_all
and upsert_all,
which means we can add aliases in the Active Record model.
For example,
here we are adding an alias name to
the original title attribute of Product
Before
We can notice,
it throws an error
saying unknown attribute name.
After
Aliased attributes also work with upsert_all
As it can be seen,
it does not throw an error
while using aliased attributes with insert_all
and upsert_all.
Note: The enhancement is yet to be released in the official Rails version