Best way to alias attribute names


#1

We are using a legacy DB and would like to alias columns on the relation so we can query attributes with our own terminology. I see it’s possible to add a :meta key on the type with a possible qualified :sql_expr, but it’s a rather tedious interface. Is there a better way to accomplish this task?


#2

There’s also attribute :user_id, Types::Int.meta(alias: :id) which seems to be the simplest option I have found (consult the API -> rom -> Attribute).

EDIT
There’s a direct link to Attribute definition.


#3

Thank you @apohllo

I have confirmed this works well with SQLite, but for some reason it is not working correctly with tinytds sequel adapter.

# schema(infer: false) do
#   attribute :product_type, Types::String.meta(alias: :producttype)
# end

[1] pry(main)> ProductsRepo.open.products.where(product_type: 'Carpet').first
Sequel::DatabaseError: TinyTds::Error: Invalid column name 'PRODUCT_TYPE'. 

Not sure if the issue is a rom thing or a sequel thing