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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium does not keep the table? euras 1 444 Jun-05-2021, 11:17 AM
Last Post: Monish
  Need help scraping wikipedia table bborusz2 6 764 Dec-01-2020, 11:31 PM
Last Post: snippsat
  Inserting data from a table to another (in same db) firebird 5 673 Oct-05-2020, 06:04 AM
Last Post: buran
  Help: Beautiful Soup - Parsing HTML table ironfelix717 2 804 Oct-01-2020, 02:19 PM
Last Post: snippsat
  Web Scraping Inquiry (Extracting content from a table in asubdomain) DustinKlent 3 1,721 Aug-17-2020, 10:10 AM
Last Post: snippsat
  Extract data from a table Bob_M 3 785 Aug-14-2020, 03:36 PM
Last Post: Bob_M
  Scraping a dynamic data-table in python through AJAX request filozofo 1 1,337 Aug-14-2020, 10:13 AM
Last Post: kashcode
  [Django] Getting exception: "no such table: auth_user" SheeppOSU 3 1,712 Jul-11-2020, 06:06 AM
Last Post: SheeppOSU
  scraping multiple pages from table bandar 1 692 Jun-27-2020, 10:43 PM
Last Post: Larz60+
  Flask export/upload database table in cvs/xlsx format steve87bg 4 1,830 Jun-19-2020, 01:46 PM
Last Post: steve87bg

Forum Jump:

User Panel Messages

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