title: SQLAlchemy generating query in loop with contains
body: <p>I'm building a web app in Flask that involves some SQLAlchemy.  I have a function "get_team()" that is driving me bonkers.</p>
  
  <pre>
      def get_team(playerlist)
          cond = and_(*[Team.users.contains(p) for p in playerlist ])
          q = Team.query.filter(cond)
           ...
  </pre>
  
  <p>I keep getting the error:  "AttributeError: 'unicode' object has no attribute '_sa_instance_state'".  Here's what the models look like:</p>
  
  <pre>
  
  class Team(db.Model):                                                            
      __tablename__ = 'teams'                                                      
  
      id = db.Column(db.Integer, primary_key=True)                                 
      users = association_proxy("user_associations", "user", creator=lambda u: Teaming(user=u))
  
      def __repr__(self):                                                          
          s = ""                                                                   
          for u in self.users:                                                     
              s = s + u.username + ", "                                            
  
          return "Team {tid}: {users_string}".format(tid = self.id, users_string=s)
  
  class Teaming(db.Model):                                                         
      __tablename__ = 'teaming'                                                    
  
      team_id = db.Column(db.Integer, db.ForeignKey('teams.id'), primary_key=True) 
      user_id = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True) 
  
      user = db.relationship("User", backref="team_associations")                  
      team = db.relationship("Team", backref="user_associations")                  
  
      def __repr__(self):                                                          
          return "".format(uid = self.user_id, tid = self.team_id)
  
  class User(UserMixin, db.Model):                                                 
      __tablename__ = 'users'                                                      
  
      id = db.Column(db.Integer, primary_key=True)                                 
  
      email = db.Column(db.String(64), unique=True, index=True)                    
      username = db.Column(db.String(64), unique=True, index=True)                 
      password_hash = db.Column(db.String(128))                                    
      confirmed = db.Column(db.Boolean, default=False)                             
  
      teams = association_proxy("team_associations", "team", creator = lambda t: Teaming(team=t))
  
  </pre>
  
  <p>Any direction would be greatly appreciated!</p>