Difference between revisions of "SQLAlchemy Notes"

From PeformIQ Upgrade
Jump to navigation Jump to search
Line 31: Line 31:




[[Category::SQLAlchemy]]
[[Category:SQLAlchemy]]
[[Category::Flask]]
[[Category:Flask]]

Revision as of 09:51, 31 May 2017

Joins

From PIQ_Admin /CRM/Contacts

sql = select([Contact.Contact_ID, Contact.FirstName, Contact.LastName, Contact.Phone, Contact.MobilePhone, Contact.Account_FK, Account.Name])\
          .where(Contact.Account_FK == Account.Account_ID).order_by(Contact.LastName, Contact.FirstName)

ctx.Contacts = db.session.execute(sql)

Failed experiments:

# ctx.Contacts = Contact.query.filter_by(Owner_FK=ctx.User.User_ID).all()

# j = join(Contact, Account, Contact.Account_FK == Account.Account_ID)

# stmt = db.session.execute(select([Contact.Contact_ID, Account.Account_ID])).select_from(j)

filter_by() vs. filter()

Links:

  • a