Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_role not querying all records irrespective of record #569

Closed
siddushar opened this issue Oct 20, 2021 · 1 comment
Closed

with_role not querying all records irrespective of record #569

siddushar opened this issue Oct 20, 2021 · 1 comment

Comments

@siddushar
Copy link

siddushar commented Oct 20, 2021

User.with_role(:approver)

 User Load (5.5ms)  SELECT "users".* FROM "users" INNER JOIN "users_roles" ON "users_roles"."user_id" = "users"."id" INNER JOIN "roles" ON "roles"."id" = "users_roles"."role_id" WHERE (((roles.name = 'approver') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) /* loading for inspect */ LIMIT $1  [["LIMIT", 11]]

Role Model

class Role < ApplicationRecord
  has_and_belongs_to_many :users, join_table: :users_roles

  belongs_to :resource, polymorphic: true, touch: true
end

User Model

class User < ApplicationRecord
  rolify before_add: :assign_child_roles
  rolify after_add: :remove_requested_role
end

When i'm trying to query all users with approval roles. It does not find all users(irrespective of resource). It find all users who has approval role and whose resource type is nil.

@siddushar
Copy link
Author

Duplicate - #597

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

No branches or pull requests

1 participant