You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Asking if a user can read an author, shouldn't instantiate all the author's books in order to check the ability:
author.books.loaded?# => false. This is good.Ability.new(user).can?(:read,author)author.books.loaded?# => true. This is BAD. There could be millions of records here.
Ideally, given all the defined abilities on Author are defined using the best practice of hash conditions, can? should be able to leverage accessible_by like this:
Steps to reproduce
You can find a full gist demonstrating the problem and potential solution in here.
Given the following code:
Asking if a user can read an author, shouldn't instantiate all the author's books in order to check the ability:
Ideally, given all the defined abilities on
Author
are defined using the best practice of hash conditions,can?
should be able to leverageaccessible_by
like this:Expected behavior
The ability is checked without instantiating an unlimited number of records in memory.
Actual behavior
Relationships involved in the hash conditions are called potentially instantiating an unlimited number of records in memory.
System configuration
Rails version: 7.0.4
Ruby version: 3.0.2
CanCanCan version: 3.4.0
The text was updated successfully, but these errors were encountered: