ruby-on-rails 数组元素的Arel节点(后缀运算符)

fcg9iug3  于 2022-11-19  发布在  Ruby
关注(0)|答案(1)|浏览(120)

是否存在后缀运算符访问数组元素的arel节点,如下所示:

column = Table.arel_table[:column]
low = here_magic_happens(column, '[1]')
Table.where(low.eq nil).or(Table.where(low.gt 5))
# should result in this where clause:
# "table"."column"[1] IS NULL OR "table"."column"[1] > 5
slwdgvem

slwdgvem1#

5年了,我还没找到比这更好的:

low =  Arel.sql("column[#{index}]")
Table.where(low.eq nil).or(Table.where(low.gt 5))

相关问题