From 8cb9460437eddde6952fbebbc969203cd4d00294 Mon Sep 17 00:00:00 2001 From: Olli Huotari Date: Mon, 20 Aug 2012 11:17:26 +0300 Subject: association_basics, updated how inverse_of works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed bug in the example code. A bit related to rails issue in  https://github.com/rails/rails/issues/3223 --- guides/source/association_basics.textile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/association_basics.textile b/guides/source/association_basics.textile index d4c0a1ba74..f6b1a0ef7a 100644 --- a/guides/source/association_basics.textile +++ b/guides/source/association_basics.textile @@ -520,7 +520,7 @@ By default, Active Record doesn't know about the connection between these associ c = Customer.first -o = c.orders.first +o = c.orders[0] c.first_name == o.customer.first_name # => true c.first_name = 'Manny' c.first_name == o.customer.first_name # => false @@ -542,7 +542,7 @@ With these changes, Active Record will only load one copy of the customer object c = Customer.first -o = c.orders.first +o = c.orders[0] c.first_name == o.customer.first_name # => true c.first_name = 'Manny' c.first_name == o.customer.first_name # => true @@ -550,6 +550,7 @@ c.first_name == o.customer.first_name # => true There are a few limitations to +inverse_of+ support: +* They do not work with methods that invoke new query. E.g. using c.orders.first instead of c.orders[0] in the code above * They do not work with :through associations. * They do not work with :polymorphic associations. * They do not work with :as associations. -- cgit v1.2.3 From 81d596aa7f7db69b27fda1c7e732a204b81d4b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 20 Aug 2012 15:51:35 -0300 Subject: Revert "association_basics, updated how inverse_of works" This reverts commit 8cb9460437eddde6952fbebbc969203cd4d00294. Reason: #7377 was merged and it fixes this behavior. --- guides/source/association_basics.textile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/source/association_basics.textile b/guides/source/association_basics.textile index f6b1a0ef7a..d4c0a1ba74 100644 --- a/guides/source/association_basics.textile +++ b/guides/source/association_basics.textile @@ -520,7 +520,7 @@ By default, Active Record doesn't know about the connection between these associ c = Customer.first -o = c.orders[0] +o = c.orders.first c.first_name == o.customer.first_name # => true c.first_name = 'Manny' c.first_name == o.customer.first_name # => false @@ -542,7 +542,7 @@ With these changes, Active Record will only load one copy of the customer object c = Customer.first -o = c.orders[0] +o = c.orders.first c.first_name == o.customer.first_name # => true c.first_name = 'Manny' c.first_name == o.customer.first_name # => true @@ -550,7 +550,6 @@ c.first_name == o.customer.first_name # => true There are a few limitations to +inverse_of+ support: -* They do not work with methods that invoke new query. E.g. using c.orders.first instead of c.orders[0] in the code above * They do not work with :through associations. * They do not work with :polymorphic associations. * They do not work with :as associations. -- cgit v1.2.3 From 9356d1b2d48a7134523ae3ccad7bd80c3ccaa30e Mon Sep 17 00:00:00 2001 From: Soon Van Date: Tue, 21 Aug 2012 23:37:47 -0400 Subject: giving a pause usually made for e.g. in sentences [ci skip] --- guides/source/migrations.textile | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'guides') diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile index 06e85e5914..a7de21b754 100644 --- a/guides/source/migrations.textile +++ b/guides/source/migrations.textile @@ -14,7 +14,7 @@ Migrations also allow you to describe these transformations using Ruby. The great thing about this is that (like most of Active Record's functionality) it is database independent: you don't need to worry about the precise syntax of +CREATE TABLE+ any more than you worry about variations on +SELECT *+ (you can -drop down to raw SQL for database specific features). For example you could use +drop down to raw SQL for database specific features). For example, you could use SQLite3 in development, but MySQL in production. In this guide, you'll learn all about migrations including: @@ -123,10 +123,10 @@ database independent way (you'll read about them in detail later): * +rename_column+ * +remove_reference+ -If you need to perform tasks specific to your database (for example create a +If you need to perform tasks specific to your database (e.g., create a "foreign key":#active-record-and-referential-integrity constraint) then the +execute+ method allows you to execute arbitrary SQL. A migration is just a -regular Ruby class so you're not limited to these functions. For example after +regular Ruby class so you're not limited to these functions. For example, after adding a column you could write code to set the value of that column for existing records (if necessary using your models). @@ -165,7 +165,7 @@ config.active_record.timestamped_migrations = false The combination of timestamps and recording which migrations have been run allows Rails to handle common situations that occur with multiple developers. -For example Alice adds migrations +20080906120000+ and +20080906123000+ and Bob +For example, Alice adds migrations +20080906120000+ and +20080906123000+ and Bob adds +20080906124500+ and runs it. Alice finishes her changes and checks in her migrations and Bob pulls down the latest changes. When Bob runs +rake db:migrate+, Rails knows that it has not run Alice's two migrations so it executes the +up+ method for each migration. @@ -182,7 +182,7 @@ migration again: Rails thinks it has already run the migration and so will do nothing when you run +rake db:migrate+. You must rollback the migration (for example with +rake db:rollback+), edit your migration and then run +rake db:migrate+ to run the corrected version. -In general editing existing migrations is not a good idea: you will be creating +In general, editing existing migrations is not a good idea. You will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead, you should write a new migration that performs the changes you require. @@ -209,8 +209,7 @@ Active Record supports the following database column types: These will be mapped onto an appropriate underlying database type. For example, with MySQL the type +:string+ is mapped to +VARCHAR(255)+. You can create -columns of types not supported by Active Record when using the non-sexy syntax, -for example +columns of types not supported by Active Record when using the non-sexy syntax such as create_table :products do |t| @@ -255,7 +254,7 @@ by Active Record). h4. Creating a Standalone Migration -If you are creating migrations for other purposes (for example to add a column +If you are creating migrations for other purposes (e.g., to add a column to an existing table) then you can also use the migration generator: @@ -309,7 +308,7 @@ class RemovePartNumberFromProducts < ActiveRecord::Migration end -You are not limited to one magically generated column, for example +You are not limited to one magically generated column. For example $ rails generate migration AddDetailsToProducts part_number:string price:decimal @@ -334,7 +333,7 @@ NOTE: The generated migration file for destructive migrations will still be old-style using the +up+ and +down+ methods. This is because Rails needs to know the original data types defined when you made the original changes. -Also the generator accepts column type as +references+(also available as +belongs_to+), for instance +Also, the generator accepts column type as +references+(also available as +belongs_to+). For instance $ rails generate migration AddUserRefToProducts user:references @@ -362,7 +361,7 @@ following modifiers: * +scale+ Defines the scale for the +decimal+ fields * +polymorphic+ Adds a +type+ column for +belongs_to+ associations -For instance running +For instance, running $ rails generate migration AddDetailsToProducts price:decimal{5,2} supplier:references{polymorphic} @@ -541,8 +540,8 @@ support":#active-record-and-referential-integrity. If the helpers provided by Active Record aren't enough you can use the +execute+ method to execute arbitrary SQL. -For more details and examples of individual methods, check the API documentation, -in particular the documentation for +For more details and examples of individual methods, check the API documentation. +In particular the documentation for "ActiveRecord::ConnectionAdapters::SchemaStatements":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html (which provides the methods available in the +up+ and +down+ methods), "ActiveRecord::ConnectionAdapters::TableDefinition":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html @@ -644,7 +643,7 @@ down to, but not including, 20080906120000. h4. Rolling Back -A common task is to rollback the last migration, for example if you made a +A common task is to rollback the last migration. For example, if you made a mistake in it and wish to correct it. Rather than tracking down the version number associated with the previous migration you can run @@ -839,7 +838,7 @@ An error has occurred, this and all later migrations canceled: undefined method `fuzz' for # -A fix for this is to create a local model within the migration. This keeps rails +A fix for this is to create a local model within the migration. This keeps Rails from running the validations, so that the migrations run to completion. When using a faux model, it's a good idea to call -- cgit v1.2.3