Faveod / arel-extensions

Extending Arel
MIT License
142 stars 24 forks source link

Cast into arrays (postgreSQL) #86

Open fdutey opened 2 years ago

fdutey commented 2 years ago

Hi,

I couldn't find a solution to cast array types with arel extensions. According to the source code, only "raw" types are allowed but not things like int[].

Is there a workaround? Thanks

Edit: my (very poor) workaround looks like this

table = scope.arel_table
 version = table[:version]

 split_version = Arel::Nodes::NamedFunction.new(
   'string_to_array', [version, Arel::Nodes::Quoted.new('.')]
)

# FIXME poor typecasting
cast = Arel.sql("#{split_version.to_sql}::int[]")

it works but im open to any "less ugly" solution because this one is just dirty as hell