python - SQLAlchemy ORM Inserting Related Objects without Selecting Them -


In this, this object describes the process of creating relationships almost the following way. Let me have a table article, a table keyword, and a table article that creates many relationships. ) .one () keyword1 = Meta. Session.query (keyword) .Filter (id = 1) .one () keyword2 = Meta Session.key (keyword) .filter (id = 2) .one () article .keywords = [Keyword1, keyword2] meta.Session.commit ()

I already have a question The primary key ID numbers for the keywords are, so I want to add all those IDs to the article_keyword table, this article is related to the problem. To do this with ORM, I have to select all the keywords from the database, without any Adds too many overheads for the reason.

Is there a way to make it to choose the keywords without running any SQL relationship?

Unfortunately the database of the object can not be sensible without the ORM query. However you can easily go around the ORM and put it in the association table. Assume that article_keyword is an table object:

  meta.Session.execute (article_keyword.date (article_keyword.article_id == 1)) meta.Session.execute (Article_keyword_id ': 1,' keyword_id ': 2},])  

If you If the ORM moves around, the preloaded archives are not updated to reflect changes in the database. If you need to refresh the collection call session again. This next time it is accessed, then the collection will be due to reloading.

  meta.Session.expire (article, ['keyword'])  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -