Python Forum
Fetching data from multiple tables in a single request.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fetching data from multiple tables in a single request.
I am unable to get all the data from multiple tables in a single request.
Here this is my code.
class maindevotee(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(225))
    phonenumber = db.Column(db.String(225))
    gothram = db.Column(db.String(225))
    date = db.Column(db.String(50))
    address = db.Column(db.String(250))

    def json(self):
        return {'id':, 'name', 'phonenumber': self.phonenumber, 'gothram': self.gothram,
                'date':, 'address': self.address}

class relatives(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    main_id = db.Column(db.Integer, db.ForeignKey(''), nullable=False)
    name = db.Column(db.String(225))
    star = db.Column(db.String(225))
    gender = db.Column(db.String(45))
    relation = db.Column(db.String(45))

    def json(self):
        return {'main_id': self.main_id, 'name':, 'star',
                'gender': self.gender, 'relation': self.relation}
class services(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    main_id = db.Column(db.Integer, db.ForeignKey(''), nullable=False)
    pooja = db.Column(db.String(225))
    god = db.Column(db.String(225))
    price = db.Column(db.Float)
    donation = db.Column(db.String(225))
    booking_fromdate = db.Column(db.String(50))
    booking_todate = db.Column(db.String(50))
    prasadam = db.Column(db.String(225))

    def json(self):
        return {'main_id': self.main_id, 'pooja': self.pooja, 'god': self.god,
                'price': self.price, 'donation': self.donation, 'booking_fromdate': self.booking_fromdate,
                'booking_todate': self.booking_todate, 'prasadam': self.prasadam}
These are all my tables in a database.
and how to fetch all my data from multiple tables.
can i use foreign key to fetch data from multiple tables in a database.
Here this is what i am use this code to fetch data from multiple tables.
data = db.session.query(maindevotee, relatives, services)\
    (maindevotee.phonenumber == '3251469870')
    & ( == relatives.main_id)
    & ( == services.main_id)

def get_data():
    return [data.json(get) for get in data.query.all()]

def getdata():
    return jsonify({'Devotee list': data.get_data()})
If i run this code it will raise an error
AttributeError: 'result' object has no attribute 'get_data'
Please help me to give your reply !

Possibly Related Threads…
Thread Author Replies Views Last Post
  Ploting single column with multiple category drunkenneo 1 328 May-26-2021, 04:51 PM
Last Post: jefsummers
  Load the data from multiple source files to one table amy83 2 259 Apr-27-2021, 12:33 AM
Last Post: Pedroski55
  API Gateway to manage multiple API's get put data robsuttonjr 2 491 Mar-09-2021, 04:09 PM
Last Post: robsuttonjr
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 844 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  How to filter out Column data From Multiple rows data? firaki12345 10 906 Feb-06-2021, 04:54 AM
Last Post: buran
  Inserting multiple rows in a single request. swaroop 2 455 Jan-11-2021, 01:34 PM
Last Post: swaroop
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 468 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  How to fill parameter with data from multiple columns CSV file greenpine 1 328 Dec-21-2020, 06:50 PM
Last Post: Larz60+
  Load data from One oracle Table to Multiple tables amy83 1 372 Dec-02-2020, 01:57 AM
Last Post: Larz60+
  getting back both: the map and the data from a request via apollo 0 410 Sep-26-2020, 11:28 AM
Last Post: apollo

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020