Note that there are some explanatory texts on larger screens.

plurals
  1. POFlask SQLAlchemy - Need Help Mapping 3 Classes together
    primarykey
    data
    text
    <p>So I've spent some time on this and keep running around in circles and getting nowhere so I figured I'd come to the experts!</p> <p>Using <code>Flask 0.9</code> and <code>SQLAlchemy 0.7.9</code> I'm attempting to create a Gallery page which has a collection of Gallery's. Each gallery has a collection of sub galleries and each sub gallery has a collection of photo's. My first attempt shown below clearly does not work:</p> <pre><code>class Gallery(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(64)) subgals = db.relationship('SubGallery', backref='author', lazy='dynamic') def __repr__(self): return '&lt;Gallery - %r&gt;' % (self.title) class SubGallery(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(64)) photos = db.relationship('Photo', backref='author', lazy='dynamic') gallery_id = db.Column(db.Integer, db.ForeignKey('gallery.id')) def __repr__(self): return '&lt;Gallery - %r&gt;' % (self.title) class Photo(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(64)) href = db.Column(db.String(128)) subgallery_id = db.Column(db.Integer, db.ForeignKey('subgallery.id')) def __repr__(self): return '&lt;Photo - %r&gt;' % (self.title) </code></pre> <p>and returns this error:</p> <pre><code>sqlalchemy.exc.ArgumentError: Could not determine join condition between parent/child tables on relationship SubGallery.photos. Specify a 'primaryjoin' expression. If 'secondary' is present, 'secondaryjoin' is needed as well. </code></pre> <p>I've been researching alternate relationship configurations but am not 100% sure what I need. My gut tells me I need an <code>Adjacency Relationship</code> but I haven't been able to get very far with it. I attempted a many to many mapping but I haven't seen much material how to map 3 classes together.</p> <p>I REALLY appreciate any input and insight you all have to offer with this and thanks!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload