In the SQLAlchemy ORM tutorial, it describes the process of creating object relations roughly as follows. Let's pretend I have a table Articles, a table Keywords, and a table Articles_Keywords which creates a many-many relationship.
article = meta.Session.query(Article).filter(id=1).one()
keyword1 = meta.Session.query(Keyword).filter(id=1).one()
keyword2 = meta.Session.query(Keyword).filter(id=2).one()
article.keywords = [keyword1,keyword2]
meta.Session.commit()
I already have the primary key ID numbers for the keywords in question, so all I need to do is add those IDs to the Articles_Keywords table, linked to this article. The problem is that in order to do that with the ORM, I have to select all of the Keywords from the database, which adds a lot of overhead for seemingly no reason.
Is there a way to create this relationship without running any SQL to select the keywords?