Nov-21-2018, 09:23 AM
(This post was last modified: Nov-21-2018, 09:35 AM by Gribouillis.)
Good afternoon, I have been beating my head against a wall with an issue for 2 weeks and was hoping you can help...I'm trying to do a one-to-many relationship...between two entities, Church (as in a church building), and minister (as in leaders of a church), there are multiple ministers for any one church...simple right? I am trying to return the name of a church, the church ID, and the ministers that have that church as a "home assembly". Additionally, when returning ministers (from the MinisterModel) I want to return the Name of the minister, the Minister ID, and the home_assembly (a json object of all the info based on church_id).
Can you PLEASE help with this, I feel like if I get over this hump everything else will make sense.
Can you PLEASE help with this, I feel like if I get over this hump everything else will make sense.
class ChurchModel(db.Model): __tablename__ = 'churches' church_id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(80)) ministers = db.relationship('MinisterModel', backref='church', lazy='dynamic') ... def json(self): # What I want --> SELECT * from minister where home_assembly_id == self.church_id # Attempt 317: ministers.query().filter(ministers.home_assembly_id == self.church_id) return {'name': self.name, 'church_id': self.church_id, 'ministers': **?????*** } ... class MinisterModel(db.Model): __tablename__ = 'ministers' minister_id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(80)) # church = db.relationship('ChurchModel') # join church_id = db.Column(db.Integer, db.ForeignKey('churches.church_id')) ... def json(self): # Return name, minister_id and minister home church return {'name': self.name, 'minister_id': self.minister_id, 'church': self.church_id}