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
  Scrap text out of td table from URLS Gochix2020 4 150 Aug-03-2019, 02:56 AM
Last Post: Larz60+
  convert html table to json bhojendra 5 149 Jul-30-2019, 07:53 PM
Last Post: DeaD_EyE
  How to capture Single Column from Web Html Table? ahmedwaqas92 5 285 Jul-29-2019, 02:17 AM
Last Post: ahmedwaqas92
  table from wikipedia flow50 5 404 Jul-01-2019, 07:12 PM
Last Post: snippsat
  get link and link text from table metulburr 5 263 Jun-13-2019, 07:50 PM
Last Post: snippsat
  Sqlalchemy foreign key problem IMuriel 1 282 May-01-2019, 03:32 PM
Last Post: Ecniv
  problem using drop down list to filter table. darktitan 1 288 Mar-27-2019, 09:57 PM
Last Post: nilamo
  flask-SQLAlchemy query with keyword as function argument pascale 2 345 Mar-13-2019, 08:45 PM
Last Post: Ecniv
  browser table value counting rudolphyaber 0 223 Feb-21-2019, 03:47 PM
Last Post: rudolphyaber
  Python Selenium getting table element trengan 2 721 Dec-31-2018, 03:02 PM
Last Post: trengan

Forum Jump:


Users browsing this thread: 1 Guest(s)