squeel
squeel copied to clipboard
Convert column
I have a column of type String in the User model, this column is an array that is saved as a string. I need to check if there is an element in that array with the where clause. How can I do it?
I thought something like this:
scope :notified, ->(user){ where{array(tags).in [user.id] } }
But it does not work.
This did not work, but it was by the generated sql order in the clause where.
scope :notified, ->(user){ where{user.id == any(cast(tags.as 'int[]')) } }
SQL: SELECT "users".* FROM "users" WHERE any(cast("users"."tags" AS int[])) = 1