Last active
May 10, 2017 13:51
-
-
Save Naggi-Goishi/e216b3262827a57ae653a99712b22399 to your computer and use it in GitHub Desktop.
ActiveRecord::QueryMethods#limitとActiveRecord::FinderMethods#take ref: http://qiita.com/Naggi-Goishi/items/856a7698f167efdb2a17
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
twelves = User.where(age: 12) | |
# ActiveRecord::QueryMethods#limitを使用する | |
twelves.limit(3) | |
# User Load (4.9ms) SELECT `users`.* FROM `users` WHERE `users`.`age` = '12' LIMIT 3 | |
#=> <#ActiveRecord::Relation [<#User id: 1, name: "ゴン=フリークス", age: 12>, <#User id: 2, name: "キルア=ゾルディック", age: 12>, <#User id: 3, name: "ピーター・パン", age: 12>]> | |
# ActiveRecord::FinderMethods#takeを使用する | |
twelves.take(3) | |
#=> [<#User id: 1, name: "ゴン=フリークス", age: 12>, <#User id: 2, name: "キルア=ゾルディック", age: 12>, <#User id: 3, name: "ピーター・パン", age: 12>] |
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
twelves.limit(3).class | |
# => User::ActiveRecord_Relation | |
twelves.take(3).class | |
# => Array |
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
User.where(age: 12).take(3) |
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
User Load (4.9ms) SELECT `users`.* FROM `users` WHERE `users`.`age` = '12' |
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
User Load (4.9ms) SELECT `users`.* FROM `users` WHERE `users`.`age` = '12' LIMIT 3 |
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
twelves = User.where(age: 12).limit(3) | |
twelves = twelves.limit(5) |
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
twelves = User.where(age: 12).limit(3) |
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
User Load (4.9ms) SELECT `users`.* FROM `users` WHERE `users`.`age` = '12' LIMIT 3 |
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
twelves = twelves.limit(5) |
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
User Load (4.9ms) SELECT `users`.* FROM `users` WHERE `users`.`age` = '12' LIMIT 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment