Bottom Page

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.
Larz60+ wrote Nov-22-2018, 10:28 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  scraping multiple pages from table bandar 1 112 Jun-27-2020, 10:43 PM
Last Post: Larz60+
  Flask export/upload database table in cvs/xlsx format steve87bg 4 153 Jun-19-2020, 01:46 PM
Last Post: steve87bg
  Scraping a dynamic data-table in python through AJAX request filozofo 0 224 Mar-18-2020, 01:44 PM
Last Post: filozofo
  Servicenow Table API bdpy9 2 256 Mar-10-2020, 08:29 PM
Last Post: bdpy9
  Imprt HTML table to array meleghengersor 2 235 Jan-23-2020, 10:23 AM
Last Post: perfringo
  How get table element zinho 5 558 Dec-28-2019, 09:25 PM
Last Post: snippsat
  Table data with BeatifulSoup gerry84 11 929 Oct-23-2019, 10:09 AM
Last Post: Larz60+
  Want to scrape a table data and export it into CSV format tahir1990 9 763 Oct-22-2019, 08:03 AM
Last Post: buran
  Beautifulsoup table question tantony 5 417 Sep-30-2019, 03:26 PM
Last Post: tantony
  Using flask to add data to sqlite3 table with PRIMARY KEY catafest 1 1,974 Sep-09-2019, 07:00 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)