I came from the .NET world where ORM NHibernate can populate foreign key relationships by loading an object by id. Loading an object simply returns the proxy of this object with the identifier you specified. This is useful for a filled relationship when I know that an identifier exists, since it does not need to query the database, thereby saving many rounds.
Here is my script. I have a client model that can be associated with one or more departments. These sections are statically stored in the database and can be associated with one or more clients, which requires me to model many-to-many relationships. There the route REST API in the form /api/v1/customers/123/divisionswhere I POST JSON data as a list of division identifiers {'division_ids': [1, 2, 3, 4]}. In this case (use in the real world could equal 20+ unit identifiers, I would have to issue a request to retrieve a client (id 123), as well as 4 requests to retrieve partitions.
Since I know the identifier of the partitions I want to insert, can I force SQLAlchemy to simply use the identifier rather than retrieve the objects?
Can SQLAlchemy do something like this?
source
share