Skip to content

Instantly share code, notes, and snippets.

@tell-k
Created September 14, 2012 11:22
Show Gist options
  • Save tell-k/3721387 to your computer and use it in GitHub Desktop.
Save tell-k/3721387 to your computer and use it in GitHub Desktop.
# relationship('Comment', lazy="subquery")
# ------------------------------------------
# * 取得タイミング
# * Entryを取得後、EntryのId列だけを取得して、そのId列のCommentのみを取得
#
# entry = Entry.query.filter_by(id=1).first() <- タイミングここ
# entry.comments
#
# * 発行SQL
# 1. SELECT * FROM entries WHERE entries.id = 1 LIMIT 1
# 2. SELECT comments.*, anon_1.entries_id
# FROM (
# SELECT entries.id AS entries_id
# FROM entries
# WHERE entries.id = 1 LIMIT 1
# ) AS anon_1
# INNER JOIN comments
# ON anon_1.entries_id = comments.entry_id
# ORDER BY anon_1.entries_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment