title: filtering multiple columns in flask/sqlalchemy
body: <p>I'm new to flask/sqlalchemy and have been trying to use filters to reject POST event when a resource in my recipe database already exist. </p>
  
  <p>So I want to check if, for a given user (<strong>id</strong>), a <strong>recipename</strong> already exists. I do this by:</p>
  
  <pre><code>exists = db.session.query(Recipe).filter_by(rname=recipename, id=id).scalar()
  </code></pre>
  
  <p>This doesn't seem to work, though it should be if you follow my debug:</p>
  
  <p>In my code, I broke it down and I've put the following lines:</p>
  
  <pre><code>print '1', db.session.query(Recipe).filter_by(id=id).scalar()
  
  print '2', db.session.query(Recipe).filter_by(rname=recipename).scalar()
  
  print '3', db.session.query(Recipe).filter_by(rname=recipename, id=id).scalar()
  </code></pre>
  
  <p>1st POST attempt with rname=test :</p>
  
  <pre><code>1 &lt;__main__.Recipe object at 0x103cff490&gt;
  
  2 None
  
  3 None
  </code></pre>
  
  <p>This makes sense as only the user id should return non-zero response, since the recipe has not been posted yet.  </p>
  
  <p>2nd POST attempt with rname=test :</p>
  
  <pre><code>1 &lt;__main__.Recipe object at 0x103cff350&gt;
  
  2 &lt;__main__.Recipe object at 0x103cff390&gt;
  
  3 None
  </code></pre>
  
  <p>As expected, (1) and (2) are not None, as rname=test now also exists. But why is (3) still returning None?</p>
  
  <p>When I drop the .scalar() off print statement 3, the query looks correct:</p>
  
  <pre><code>SELECT recipes.id AS recipes_id, recipes.rname AS recipes_rname, recipes.customer_id AS recipes_customer_id, recipes.date AS recipes_date, recipes.done AS recipes_done
  FROM recipes
  WHERE recipes.rname = :rname_1 AND recipes.id = :id_1
  </code></pre>
  
  <p>I can also select the row from my postgres database.</p>
  
  <p>Any help would be much appreciated!</p>