Difference between revisions of "SQLAlchemy Notes"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (Created page with " =Joins= From PIQ_Admin /CRM/Contacts <pre> sql = select([Contact.Contact_ID, Contact.FirstName, Contact.LastName, Contact.Phone, Contact.MobilePhone, Contact.Accou...") |
PeterHarding (talk | contribs) (→Joins) |
||
Line 5: | Line 5: | ||
<pre> | <pre> | ||
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) | |||
</pre> | </pre> | ||
Line 15: | Line 14: | ||
<pre> | <pre> | ||
# 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) | |||
</pre> | </pre> | ||
Revision as of 09:50, 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
[[Category::SQLAlchemy]] [[Category::Flask]]