Custom QueryBuilder doesn't add methods to base class
Because resource scopes (e.g. where) are delegated to the query builder during the definition of resource, there isn't a way for custom query builders to add methods on the base resource/class.
It would be preferential for there to be some degree of scope definition support (a la ActiveRecord), but maybe there's a reasonable workaround that doesn't require explicit delegation in the resource class?
Today:
class CustomQueryBuilder < JsonAPIClient::Query::Builder
def recent
where(created_at_gt: 3.days.ago)
end
end
class User < API::Base
self.query_builder = CustomQueryBuilder
def self.recent
_new_scope.recent
end
end
Future?
class User < API::Base
scope :recent, -> { where(created_at_gt: 3.days.ago) }
end
@coreyward I don't think it's necessary to go through the CustomQueryBuilder for that. I think you can just use the following:
class User < API::Base
def self.recent
where(created_at_gt: 3.days.ago)
end
end
Scopes are really just class methods with a query defined in them: http://guides.rubyonrails.org/active_record_querying.html#scopes
I may be misunderstanding your question though 😄