Skip to content

Instantly share code, notes, and snippets.

@pawl
pawl / in_loading.py
Last active December 28, 2017 15:19
Example of a custom "IN()" relationship loading strategy in sqlalchemy
from collections import defaultdict
from sqlalchemy import create_engine, Column, ForeignKey, Integer
from sqlalchemy.orm import relationship, scoped_session, sessionmaker
from sqlalchemy.orm.attributes import set_committed_value
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('mysql://root@localhost/test?charset=utf8mb4',
convert_unicode=True,
echo=True)