luckyframework / avram

A Crystal database wrapper for reading, writing, and migrating Postgres databases.

Home Page:https://luckyframework.github.io/avram/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a reset_defaults method to queries

jwoertink opened this issue · comments

If you have a query class that sets some defaults, there may be some instance (e.g. an admin section) where you want to ignore those defaults. In that case, it would be helpful to have some sort of reset_defaults or maybe without_defaults method that lets you ignore those.

class ServerQuery < Server::BaseQuery
  def initialize
    defaults(&.enabled(true))
  end
end

ServerQuery.new.reset_defaults
commented

If you really wanted no defaults, why not just Server::BaseQuery.new instead? I typically only reach for a Query sub-class when I really have the need for repeated for some shared query defaults.

That's actually a really good thought. In my case, the Server::BaseQuery was monkey patched which I just initially ignored, but now thinking about it, it shouldn't be. That would actually solve the issues I have here.. Hmm, yeah, maybe this isn't needed at all 🤔

I'm closing this since it came about as a hack to a hack and it's not actually necessary