title: changinge from sqlalchemy to postgresql and got the error with relationship
body: <p>Hi I had database many to many relation and for bestfriend one to one relationship which works perfectly with sqlalchemy now I change it to postgresql and got the</p>
  
  <p>errornvalidRequestError: On relationship <code>Users.is_bestfriend</code>, 'dynamic' loaders cannot be used with many-to-one/one-to-one relationships and/or uselist=False.</p>
  
  <blockquote>
    <p>error:</p>
  </blockquote>
  
  <pre><code>Traceback (most recent call last)
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
  
      return self.wsgi_app(environ, start_response)
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
  
      response = self.make_response(self.handle_exception(e))
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
  
      reraise(exc_type, exc_value, tb)
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
  
      response = self.full_dispatch_request()
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
  
      rv = self.handle_user_exception(e)
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
  
      reraise(exc_type, exc_value, tb)
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
  
      rv = self.dispatch_request()
  
      File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
  
      return self.view_functions[rule.endpoint](**req.view_args)
  
      File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 756, in decorated_view
  
      elif not current_user.is_authenticated():
  
      File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 338, in __getattr__
  
      return getattr(self._get_current_object(), name)
  
      File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 297, in _get_current_object
  
      return self.__local()
  
      File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 46, in &lt;lambda&gt;
  
      current_user = LocalProxy(lambda: _get_user())
  
      File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 794, in _get_user
  
      current_app.login_manager._load_user()
  
      File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 363, in _load_user
  
      return self.reload_user()
  
      File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 325, in reload_user
  
      user = self.user_callback(user_id)
  
      File "/home/peg/flask-Alembic/app/auth/view.py", line 60, in load_user
  
      return Users.query.get(int(user_id))
  
      File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 426, in __get__
  
      mapper = orm.class_mapper(type)
  
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/base.py", line 378, in class_mapper
  
      mapper = _inspect_mapped_class(class_, configure=configure)
  
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/base.py", line 355, in _inspect_mapped_class
  
      mapper._configure_all()
  
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 1129, in _configure_all
  
      configure_mappers()
  
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 2544, in configure_mappers
  
      mapper._post_configure_properties()
  
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 1660, in _post_configure_properties
  
      prop.post_instrument_class(self)
  
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/interfaces.py", line 481, in post_instrument_class
  
      self.strategy.init_class_attribute(mapper)
  
      File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/dynamic.py", line 31, in init_class_attribute
  
      "uselist=False." % self.parent_property)
  
      InvalidRequestError: On relationship Users.is_bestfriend, 'dynamic' loaders cannot be used with many-to-one/one-to-one relationships and/or uselist=False.
  </code></pre>
  
  <blockquote>
    <p>model.py:</p>
  </blockquote>
  
  <pre><code>friends = db.Table('friends',
      db.Column('user_id', db.Integer, db.ForeignKey('users.id')),
      db.Column('friend_id', db.Integer, db.ForeignKey('users.id'))
      )
  
      class Users(db.Model):
         id = db.Column(db.Integer, primary_key = True)
         name = db.Column(db.String(50), index=True)
         age= db.Column(db.Integer )
         email = db.Column(db.String(50),index=True, unique= True)
         bestfriend_id = db.Column(db.Integer, db.ForeignKey('users.id'))
  
  
         is_bestfriend = db.relationship( 'Users',lazy='dynamic',remote_side=id, post_update=True)
  
         is_friend = db.relationship('Users', #defining the relationship, Users is left side entity
              secondary = friends, #indecates association table
              primaryjoin = (friends.c.user_id == id), #condition linking the left side entity
              secondaryjoin = (friends.c.friend_id == id),#cond if link right.s ent. with assoc table
              backref = db.backref('friends', lazy = 'dynamic'),#how accessed from right
              lazy = 'dynamic'
          ) 
        #funcitons for bestfriend management
         def are_bestfriends(self, user):
               return self.is_bestfriend == user
  
          #best friends management
         def be_bestfriend(self, user):
               if not self.are_bestfriends(user):
                        self.is_bestfriend = [user] 
                        user.is_bestfriend = [self]
                        return self
  </code></pre>
  
  <blockquote>
    <p>view.py:</p>
  </blockquote>
  
  <pre><code>#best_freinds
  @layout.route('/bestFriend/&lt;name&gt;')
  @login_required
  def bestFriend(name):
      user = Users.query.filter_by(name = name).first()
      if user is None:
          flash('User %s not found.' % name)
          return redirect(url_for('index'))
      if user == g.user:
          flash('You can\'t Best Friend yourself!')
          return redirect(url_for('user', page=1,sortby='normal'))
      u = g.user.be_bestfriend(user) #got error here if I remove lazy='dynamic'
      if u is None:
          flash('Cannot be best Friend ' + name + '.')
          return redirect(url_for('user', page=1,sortby='normal'))
      db.session.add(u)
      db.session.commit()
      flash('You are now BestFriend with ' + name + '!')
      return redirect(url_for('user', page=1,sortby='normal'))
  </code></pre>