Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Convert column #427

Open
eugenio-caicedo opened this issue Aug 2, 2017 · 1 comment
Open

Convert column #427

eugenio-caicedo opened this issue Aug 2, 2017 · 1 comment

Comments

@eugenio-caicedo
Copy link

eugenio-caicedo commented Aug 2, 2017

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.

@eugenio-caicedo
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant