Last active
August 29, 2015 13:57
-
-
Save kronosapiens/9707658 to your computer and use it in GitHub Desktop.
Terminal Log for Arel "includes" vs. "joins"
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
[1] pry(Boat)> ActiveRecord::Base.logger = Logger.new(STDOUT) | |
=> #<Logger:0x00000104286068 | |
@default_formatter=#<Logger::Formatter:0x00000104286040 @datetime_format=nil>, | |
@formatter=nil, | |
@level=0, | |
@logdev= | |
#<Logger::LogDevice:0x00000104285ff0 | |
@dev=#<IO:<STDOUT>>, | |
@filename=nil, | |
@mutex= | |
#<Logger::LogDevice::LogDeviceMutex:0x00000104285fc8 | |
@mon_count=0, | |
@mon_mutex=#<Mutex:0x00000104285f78>, | |
@mon_owner=nil>, | |
@shift_age=nil, | |
@shift_size=nil>, | |
@progname=nil> | |
[2] pry(Boat)> j = joins(:classifications).where(:classifications => {:name => "Sailboat"} ) | |
D, [2014-03-22T13:00:42.561033 #17704] DEBUG -- : Boat Load (0.4ms) SELECT "boats".* FROM "boats" INNER JOIN "boat_classifications" ON "boat_classifications"."boat_id" = "boats"."id" INNER JOIN "classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "classifications"."name" = 'Sailboat' | |
=> [#<Boat id: 1, name: "H 28", length: 27, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 2, name: "Nacra 17", length: 17, captain_id: 2, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 6, name: "49er", length: 16, captain_id: 6, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 8, name: "Laser", length: 14, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 11, name: "Harpoon 4.7", length: 15, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 12, name: "Sunfish", length: 13, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">] | |
[3] pry(Boat)> j.class | |
=> ActiveRecord::Relation::ActiveRecord_Relation_Boat | |
[4] pry(Boat)> i = includes(:classifications).where(:classifications => {:name => "Sailboat"} ) | |
D, [2014-03-22T13:01:04.027861 #17704] DEBUG -- : SQL (0.5ms) SELECT "boats"."id" AS t0_r0, "boats"."name" AS t0_r1, "boats"."length" AS t0_r2, "boats"."captain_id" AS t0_r3, "boats"."created_at" AS t0_r4, "boats"."updated_at" AS t0_r5, "classifications"."id" AS t1_r0, "classifications"."name" AS t1_r1, "classifications"."created_at" AS t1_r2, "classifications"."updated_at" AS t1_r3 FROM "boats" LEFT OUTER JOIN "boat_classifications" ON "boat_classifications"."boat_id" = "boats"."id" LEFT OUTER JOIN "classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "classifications"."name" = 'Sailboat' | |
=> [#<Boat id: 1, name: "H 28", length: 27, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 2, name: "Nacra 17", length: 17, captain_id: 2, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 6, name: "49er", length: 16, captain_id: 6, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 8, name: "Laser", length: 14, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 11, name: "Harpoon 4.7", length: 15, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 12, name: "Sunfish", length: 13, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">] | |
[5] pry(Boat)> i.class | |
=> ActiveRecord::Relation::ActiveRecord_Relation_Boat | |
[6] pry(Boat)> j.each {|boat| puts boat.classifications} | |
D, [2014-03-22T13:01:36.331678 #17704] DEBUG -- : Classification Load (0.4ms) SELECT "classifications".* FROM "classifications" INNER JOIN "boat_classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "boat_classifications"."boat_id" = ? [["boat_id", 1]] | |
#<Classification:0x000001052381a0> | |
#<Classification:0x000001052413e0> | |
D, [2014-03-22T13:01:36.348813 #17704] DEBUG -- : Classification Load (0.2ms) SELECT "classifications".* FROM "classifications" INNER JOIN "boat_classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "boat_classifications"."boat_id" = ? [["boat_id", 2]] | |
#<Classification:0x00000105249db0> | |
#<Classification:0x00000105249ab8> | |
#<Classification:0x00000105249810> | |
D, [2014-03-22T13:01:36.350064 #17704] DEBUG -- : Classification Load (0.1ms) SELECT "classifications".* FROM "classifications" INNER JOIN "boat_classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "boat_classifications"."boat_id" = ? [["boat_id", 6]] | |
#<Classification:0x0000010525aca0> | |
#<Classification:0x0000010525a980> | |
D, [2014-03-22T13:01:36.351073 #17704] DEBUG -- : Classification Load (0.1ms) SELECT "classifications".* FROM "classifications" INNER JOIN "boat_classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "boat_classifications"."boat_id" = ? [["boat_id", 8]] | |
#<Classification:0x000001052690e8> | |
#<Classification:0x0000010526bca8> | |
D, [2014-03-22T13:01:36.352008 #17704] DEBUG -- : Classification Load (0.1ms) SELECT "classifications".* FROM "classifications" INNER JOIN "boat_classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "boat_classifications"."boat_id" = ? [["boat_id", 11]] | |
#<Classification:0x00000105271568> | |
#<Classification:0x00000105271130> | |
D, [2014-03-22T13:01:36.353029 #17704] DEBUG -- : Classification Load (0.1ms) SELECT "classifications".* FROM "classifications" INNER JOIN "boat_classifications" ON "classifications"."id" = "boat_classifications"."classification_id" WHERE "boat_classifications"."boat_id" = ? [["boat_id", 12]] | |
#<Classification:0x000001042cf3a8> | |
#<Classification:0x000001042cf100> | |
=> [#<Boat id: 1, name: "H 28", length: 27, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 2, name: "Nacra 17", length: 17, captain_id: 2, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 6, name: "49er", length: 16, captain_id: 6, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 8, name: "Laser", length: 14, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 11, name: "Harpoon 4.7", length: 15, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 12, name: "Sunfish", length: 13, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">] | |
[7] pry(Boat)> i.each {|boat| puts boat.classifications} | |
#<Classification:0x000001051b9b98> | |
#<Classification:0x000001051b9b98> | |
#<Classification:0x000001051b9b98> | |
#<Classification:0x000001051b9b98> | |
#<Classification:0x000001051b9b98> | |
#<Classification:0x000001051b9b98> | |
=> [#<Boat id: 1, name: "H 28", length: 27, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 2, name: "Nacra 17", length: 17, captain_id: 2, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 6, name: "49er", length: 16, captain_id: 6, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 8, name: "Laser", length: 14, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 11, name: "Harpoon 4.7", length: 15, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 12, name: "Sunfish", length: 13, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">] | |
[8] pry(Boat)> j.first | |
=> #<Boat id: 1, name: "H 28", length: 27, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09"> | |
[9] pry(Boat)> i.first | |
=> #<Boat id: 1, name: "H 28", length: 27, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09"> | |
[10] pry(Boat)> j.first == i.first | |
=> true | |
[11] pry(Boat)> j.first.classifications | |
=> [#<Classification id: 1, name: "Ketch", created_at: "2014-03-22 17:00:10", updated_at: "2014-03-22 17:00:10">, | |
#<Classification id: 2, name: "Sailboat", created_at: "2014-03-22 17:00:10", updated_at: "2014-03-22 17:00:10">] | |
[12] pry(Boat)> _.class | |
=> ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Classification | |
[13] pry(Boat)> i.first.classifications | |
=> [#<Classification id: 2, name: "Sailboat", created_at: "2014-03-22 17:00:10", updated_at: "2014-03-22 17:00:10">] | |
[14] pry(Boat)> _.class | |
=> ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Classification | |
[15] pry(Boat)> j.first.classifications == i.first.classifications | |
=> false | |
[16] pry(Boat)> j.first.classifications.last | |
=> #<Classification id: 2, name: "Sailboat", created_at: "2014-03-22 17:00:10", updated_at: "2014-03-22 17:00:10"> | |
[17] pry(Boat)> _.class | |
=> Classification(id: integer, name: string, created_at: datetime, updated_at: datetime) | |
[18] pry(Boat)> i.first.classifications.first | |
=> #<Classification id: 2, name: "Sailboat", created_at: "2014-03-22 17:00:10", updated_at: "2014-03-22 17:00:10"> | |
[19] pry(Boat)> _.class | |
=> Classification(id: integer, name: string, created_at: datetime, updated_at: datetime) | |
[20] pry(Boat)> j.first.classifications.last == i.first.classifications.first | |
=> true | |
[21] pry(Boat)> j.each {|boat| puts boat.classifications} | |
#<Classification:0x000001052381a0> | |
#<Classification:0x000001052413e0> | |
#<Classification:0x00000105249db0> | |
#<Classification:0x00000105249ab8> | |
#<Classification:0x00000105249810> | |
#<Classification:0x0000010525aca0> | |
#<Classification:0x0000010525a980> | |
#<Classification:0x000001052690e8> | |
#<Classification:0x0000010526bca8> | |
#<Classification:0x00000105271568> | |
#<Classification:0x00000105271130> | |
#<Classification:0x000001042cf3a8> | |
#<Classification:0x000001042cf100> | |
=> [#<Boat id: 1, name: "H 28", length: 27, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 2, name: "Nacra 17", length: 17, captain_id: 2, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 6, name: "49er", length: 16, captain_id: 6, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 8, name: "Laser", length: 14, captain_id: 1, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:10">, | |
#<Boat id: 11, name: "Harpoon 4.7", length: 15, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">, | |
#<Boat id: 12, name: "Sunfish", length: 13, captain_id: nil, created_at: "2014-03-22 17:00:09", updated_at: "2014-03-22 17:00:09">] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment