title: Typecasting values in Sequel finders
body: <p>I have a model with a numeric status column, which is mapped to symbols by the model. This works well so far but I can not use the finder mechanism of sequel with this.</p>
  
  <p>Lets take this model</p>
  
  <pre><code>class Task &lt; Sequel::Model
    finder def self.by_status(status)
      where(status: status)
    end
  end
  </code></pre>
  
  <p>With this example database:</p>
  
  <pre><code>DB.create_table(:tasks) { primary_key :id; Integer :status }
  3.times {|n| DB[:tasks].insert(status: n) }
  </code></pre>
  
  <p>With this I can use <code>Task.first_by_status(2)</code> to receive the dataset. The query behind the finder is created by the Sequel::Dataset::PlaceholderLiteralizer mechanism.</p>
  
  <p>When I add the Symbol mapping the model looks more like this:</p>
  
  <pre><code>class Task &lt; Sequel::Model
    STATES = {
      0 =&gt; :new,
      1 =&gt; :busy,
      2 =&gt; :done,
      3 =&gt; :failed,
    }.freeze
  
    finder def self.by_status(status)
      where(status: status2id(status))
    end
  
    def status=(v)
      super self.class.status2id(v)
    end
  
    def status
      STATES.fetch(super)
    end
  
    def self.status2id(sym)
      sym = sym.downcase.to_sym
      STATES.key(sym)
    end
  end
  </code></pre>
  
  <p>The modified finder method does not work anymore, because it passes a <code>Sequel::Dataset::PlaceholderLiteralizer::Argument</code> instance to <code>.status2id</code> in the recording phase.</p>
  
  <p>Is there a way to modify the arguments while using this mechanism?</p>