title: Is there a way to create a temporary column for a single query in Activerecord?
body: <p>Let's say we have a ChessPiece class with the following migration.</p>
  
  <pre><code>create_table :chess_pieces do |t|
    t.string  :type
    t.integer :row
    t.integer :column
    t.integer :game_id, index: true
  end
  </code></pre>
  
  <p>If a Bishop wanted to move from (0,0) to (7,7) then I need to check each space in between the two positions for other pieces that might be blocking my Bishop. IE if there was a Pawn on (5,5).</p>
  
  <p>I could query the database for EACH position that might have a blocking piece like this:</p>
  
  <pre><code>pieces = []
  8.times do |i|
    pieces &lt;&lt; ChessPiece.where(game_id: @game_id, row: i, column: i)
  end
  </code></pre>
  
  <p>But I want to cut down on queries. Alternatively, I could grab <strong><em>all</em></strong> the chess pieces for a game and iterate over them in Ruby, but that also seems inefficient. What I'd like to do is tell the database to combine the <code>row</code> and <code>column</code> columns together into the form "row-column" and call it <code>position</code>. That way I could run something like the following query:</p>
  
  <pre><code>ChessPiece.where(game_id: @game_id, position: ["1-1", "2-2", "3-3"])
  </code></pre>
  
  <p>How do I dynamically create this new column so I can run something like the above query? (Assume I can't just edit the database schema.)</p>