Last active
August 29, 2015 14:10
-
-
Save mrbrdo/aaa36b3490ad4e4ceec4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Commit < Sequel::Model | |
end | |
class Repository < Sequel::Model | |
one_to_many :recent_commits, :class => 'Commit', | |
eager_limit_strategy: true, | |
order: Sequel.desc(:id), | |
limit: 3 | |
end | |
# This will return all repositories with the last 3 commits loaded for each: | |
# Repository.eager(:recent_commits).all | |
# Queries generated on Postgres: | |
# SELECT * FROM "repositories" | |
# SELECT * FROM ( | |
# SELECT *, | |
# row_number() OVER (PARTITION BY "commits"."repository_id" ORDER BY "id" DESC) AS "x_sequel_row_number_x" | |
# FROM "commits" WHERE ("commits"."repository_id" IN (1)) | |
# ) AS "t1" WHERE ("x_sequel_row_number_x" <= 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment