class Author(SqlAlchemyObjectType): __model__ = AuthorRecord id = column_field(AuthorRecord.c_id) name = column_field(AuthorRecord.c_name) books = many(lambda: sql_join(Book)) book_titles = extract(books, "title")
class Book(SqlAlchemyObjectType): __model__ = BookRecord id = column_field(BookRecord.id) title = column_field(BookRecord.title) genre = column_field(BookRecord.genre) author_id = column_field(BookRecord.author_id) author = single(lambda: sql_join(Author))
class Author(SqlAlchemyObjectType): __model__ = AuthorRecord id_1 = column_field(AuthorRecord.c_id_1) id_2 = column_field(AuthorRecord.c_id_2) name = column_field(AuthorRecord.c_name) books = many(lambda: sql_join(Book, join={ Author.id_1: Book.author_id_1, Author.id_2: Book.author_id_2, }))
class Book(SqlAlchemyObjectType): __model__ = BookRecord id = column_field(column=BookRecord.c_id) title = column_field(column=BookRecord.c_title) author_id = column_field(column=BookRecord.c_author_id) author = single(lambda: sql_join(Author)) books_by_same_author = extract(author, "books") sales = single( lambda: sql_value_join(Sales, {Book.title: Sales.book_title}))