'How to combine queries with the help of the "shih tzu flag gem" in Rails?
I've used to shih tzu flag gem to make a queries, then the User and Article models, as:
class User < ApplicationRecord
belongs_to :city
...
has_flags 1 => :is_admin,
2 => :is_customer
end
class City < ApplicationRecord
has_many :cities
...
end
Then, when I make a next query to stored all city with users work to me:
city_users = City_joins(:users).where(users: {confirmed_at: nil})
but... when I make a other query to know if user is_admin it doesn't work me,
I get this errors:
city_admin = City_joins(:users).where(users: {is_admin: true})
=> ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column users.is_admin does not exist)
That's because it doesn't recognize the field "is_admin", but I'd like to query method has_flags (is_admin, is_customer)
If someone knows how to make queries with has_flags or scope and could help me, I would be very grateful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
