Python Forum
sqlalchemy DataTables::"No data available in table" when using self-joined table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sqlalchemy DataTables::"No data available in table" when using self-joined table
#1
Hello,

I need to run a query with sqlalchemy on self-joined table, I tried to use alias as suggested by many forums but no data displayed.
Please find below my code:

models.py

class Employee(db.Model):

__tablename__ = 'employee' #self referenced table

id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
surname = db.Column(db.String(200), nullable=False)
email = db.Column(db.String(200), nullable=False)
id_emp_sup = db.Column(db.Integer, db.ForeignKey("employee.id"))
#emp_sup = db.relationship('Employee',backref = 'employee')
#emp_sup = db.relationship('Employee', foreign_keys="[id_emp_sup]")
id_structure = db.Column(db.Integer, db.ForeignKey("structure.id"))
id_function = db.Column(db.Integer, db.ForeignKey("function.id"))

def __init__(self, name, surname, email, id_emp_sup, id_structure):
self.name = name
self.surname = surname
self.email = email
self.id_emp_sup = id_emp_sup
self.id_structure = id_structure
self.id_function = id_function

views.py

Emp = db.aliased(Employee)


columns = [
ColumnDT(Employee.name +' '+ Employee.surname),
ColumnDT(Emp.name +' '+ Emp.surname)
]
result = db.session.query().select_from(Employee).join(Emp)
params = request.args.to_dict()
rowTable = DataTables(params, result, columns)
return jsonify(rowTable.output_result())


I want to display the full name of each employee with his manager (identified by id_emp_sup) by using sqlalchemy datatable.
Reply


Messages In This Thread
sqlalchemy DataTables::"No data available in table" when using self-joined table - by Asma - Nov-22-2018, 02:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a table with the help of Python? emmanuelkatto 1 551 Nov-16-2023, 12:48 PM
Last Post: Larz60+
  Help Scraping links and table from link cartonics 11 1,420 Oct-12-2023, 06:42 AM
Last Post: cartonics
  Scrape table from multiple pages Nhattanktnn 1 822 Jun-07-2023, 09:35 AM
Last Post: Larz60+
  Webscraping returning empty table Buuuwq 0 1,350 Dec-09-2022, 10:41 AM
Last Post: Buuuwq
  Is it possible to grab a table off a webpage you are already logged into? cubangt 0 1,146 Mar-02-2022, 10:10 PM
Last Post: cubangt
  Scraping data from table into existing dataframe vincer58 1 1,959 Jan-09-2022, 05:15 PM
Last Post: vincer58
  Python Obstacles | American Kenpo | Wiki Scrape URL/Table and Store it in MariaDB BrandonKastning 6 2,783 Dec-29-2021, 12:38 AM
Last Post: BrandonKastning
  Suggestion request for scrapping html table Vkkindia 3 1,986 Dec-06-2021, 06:09 PM
Last Post: Larz60+
  the table is upside down phochka 1 1,676 Aug-23-2021, 04:25 PM
Last Post: snippsat
  Selenium does not keep the table? euras 1 2,167 Jun-05-2021, 11:17 AM
Last Post: Monish

Forum Jump:

User Panel Messages

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