Closed
Description
Currently returns nil if used on a AR class, and throws a non-related error if used on a scope.
THIS WAS THE ORIGINAL CONCLUSION BUT ITS INCORRECT SEE DISCUSSION:
The reasons we won't implement where is that it could be used to insecurely determine counts on data.
For exampleCustomers.where(top_secret_attribute: true).count
could be executed from the JS console to find the count of customers with the top_secret_attribute.
where
should be implemented as a scope.
We will need to add scope called __hyperstack_internal_where_scope
class ActiveRecord::Base
scope __hyperstack_internal_where_scope,
->(attrs) { where(attrs) }, # server side we just call where
filter: ->(attrs) { !attrs.detect { |k, v| self[k] != v } # client side optimization
def self.where(attrs)
__hyperstack_internal_where_scope(attrs)
end if RUBY_ENGINE == 'opal'
end
On the client side we can add the class level where
method to ActiveRecord::Base
and which simpy calls the `__hyperstack_internal_where_scope.