title: Flask-SQLAlchemy One to Many relationship failed to locate a name
body: <p>I have a Flask app with Flask-SQLAlchemy. I'm trying to make a one to many relationship from a user to a trip. I saw that, if I use the declarative_base of SQLAlchemy it works but when I use the db.Model from Flask-SQLAlchemy it dosen't work.</p>
  
  <p>I'm getting the following error: </p>
  
  <pre><code>sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper|User|User, expression 'Trip' failed to locate a name ("name 'Trip' is not defined"). If this is a class name, consider adding this relationship() to the &lt;class 'models.user.User'&gt; class after both dependent classes have been defined.
  </code></pre>
  
  <p>Here are the models:</p>
  
  <p>database.py</p>
  
  <pre><code>from flask import abort 
  from flask_sqlalchemy import SQLAlchemy 
  from sqlalchemy import exc
  
  db = SQLAlchemy()
  
  
  class Mixin(db.Model):
      __abstract__ = True
      id = db.Column(db.Integer, primary_key=True)
      date = db.Column(db.DateTime, default=db.func.now())
      date_changed = db.Column(
          db.DateTime, nullable=True, onupdate=db.func.now())
      date_to = db.Column(db.DateTime, nullable=True)
  </code></pre>
  
  <p>user.py</p>
  
  <pre><code>from database import Mixin, db
  
  class User(Mixin, db.Model):
      __tablename__ = 'User'        
      trips = db.relationship(
          'Trip',
          backref=db.backref('user', lazy='joined'),
          lazy='dynamic'
      )     
  </code></pre>
  
  <p>trip.py</p>
  
  <pre><code>from database import Mixin, db
  
  class Trip(Mixin, db.Model):
      __tablename__ = 'Trip'
      title = db.Column(db.String(100), nullable=False)
      description = db.Column(db.String(250), nullable=False)        
      user_id = db.Column(
          db.Integer,
          db.ForeignKey('User.id'),
          nullable=False
      )       
  </code></pre>