title: SQLAlchemy - Relationship across four tables?
body: <p>Here is my setup:</p>
  
  <pre><code>class User(Base):
      __tablename__ = 'users'
      user_id = Column(Integer, primary_key=True)
  
  class Object(Base):
      __tablename__ = 'objects'
      object_id = Column(Integer, primary_key=True)
      user_id = Column(Integer, ForeignKey('User.user_id'))
  
  class ObjectHistory(Base):
      __tablename__ = 'object_histories'
      history_id = Column(Integer, primary_key=True)
      object_id = Column(Integer, primary_key=True)
  
  class Action(Base):
      __tablename__ = 'actions'
      action_id = Column(Integer, primary_key=True)
  
  class ActionDetail(Base):
      __tablename__ = 'action_details'
      detail_id = Column(Integer, primary_key=True)
      history_id = Column(Integer, ForeignKey('ObjectHistory.id')
  
      object = relationship('Object', secondary='object_histories',
                            primaryjoin='ActionDetail.history_id==ObjectHistory.history_id',
                            secondaryjoin='Object.object_id==ObjectHistory.object_id',
                            backref='action_details')
  
      user = relationship('User', ????, backref='action_details')
  </code></pre>
  
  <p>How can I create the <code>user</code> relationship on ActionDetail? Is it possible? I've tried something similar to the <code>object</code> relationship above it, but to no avail.</p>