From 29bf193cadae8c0b01f565caed75eb285ba8c958 Mon Sep 17 00:00:00 2001 From: Manuel Menezes de Sequeira Date: Thu, 6 Oct 2011 21:29:58 +0100 Subject: Undid previous change which violated the convention regarding output (use "# =>") used in these guides. Corrected typo in previous correction. (Thanks for pointing this out, vijaydev.) --- .../guides/source/active_record_querying.textile | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 6b6f4d4983..81d73c4ccc 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -87,7 +87,7 @@ Using Model.find(primary_key), you can retrieve the object correspondin # Find the client with primary key (id) 10. client = Client.find(10) -=> # +# => # The SQL equivalent of the above is: @@ -104,7 +104,7 @@ h5. +first+ client = Client.first -=> # +# => # The SQL equivalent of the above is: @@ -121,7 +121,7 @@ h5. +last+ client = Client.last -=> # +# => # The SQL equivalent of the above is: @@ -138,7 +138,7 @@ h5(#first_1). +first!+ client = Client.first! -=> # +# => # The SQL equivalent of the above is: @@ -155,7 +155,7 @@ h5(#last_1). +last!+ client = Client.last! -=> # +# => # The SQL equivalent of the above is: @@ -175,7 +175,7 @@ h5. Using Multiple Primary Keys # Find the clients with primary keys 1 and 10. client = Client.find([1, 10]) # Or even Client.find(1, 10) -=> [#, #] +# => [#, #] The SQL equivalent of the above is: @@ -252,7 +252,7 @@ Invoice.find_in_batches(:include => :invoice_lines) do |invoices| end -The above will each time yield to the supplied block an arrays of 1000 invoices (or the remaining invoices, if less than 1000). +The above will each time yield to the supplied block an array of 1000 invoices (or the remaining invoices, if less than 1000). NOTE: The +:include+ option allows you to name associations that should be loaded alongside with the models. @@ -1032,7 +1032,7 @@ Suppose you want to find a client named 'Andy', and if there's none, create one Client.where(:first_name => 'Andy').first_or_create(:locked => false) -=> # +# => # The SQL generated by this method looks like this: @@ -1070,7 +1070,7 @@ to your +Client+ model. If you try to create a new +Client+ without passing an + Client.where(:first_name => 'Andy').first_or_create!(:locked => false) -=> ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank +# => ActiveRecord::RecordInvalid: Validation failed: Orders count can't be blank h4. +first_or_initialize+ @@ -1079,13 +1079,13 @@ The +first_or_initialize+ method will work just like +first_or_create+ but it wi nick = Client.where(:first_name => 'Nick').first_or_initialize(:locked => false) -=> +# => nick.persisted? -=> false +# => false nick.new_record? -=> true +# => true Because the object is not yet stored in the database, the SQL generated looks like this: @@ -1098,7 +1098,7 @@ When you want to save it to the database, just call +save+: nick.save -=> true +# => true h3. Finding by SQL -- cgit v1.2.3