aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/activerecord
diff options
context:
space:
mode:
authorRyan Bigg <radarlistener@gmail.com>2008-10-18 17:43:38 +1030
committerRyan Bigg <radarlistener@gmail.com>2008-10-18 17:43:38 +1030
commit2139a1b6812be7ca86de2df52e9776a2be4a2bf7 (patch)
tree3131e29d3582b8aa1ba1c68710f327ce2f22aa1d /railties/doc/guides/activerecord
parent09b7e351316cb87a815678241fc90af549327cf3 (diff)
parent095cafbcd7fbae3baa845b23b93c8dca93b442f8 (diff)
downloadrails-2139a1b6812be7ca86de2df52e9776a2be4a2bf7.tar.gz
rails-2139a1b6812be7ca86de2df52e9776a2be4a2bf7.tar.bz2
rails-2139a1b6812be7ca86de2df52e9776a2be4a2bf7.zip
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'railties/doc/guides/activerecord')
-rw-r--r--railties/doc/guides/activerecord/active_record_basics.txt2
-rw-r--r--railties/doc/guides/activerecord/association_basics.txt37
2 files changed, 21 insertions, 18 deletions
diff --git a/railties/doc/guides/activerecord/active_record_basics.txt b/railties/doc/guides/activerecord/active_record_basics.txt
new file mode 100644
index 0000000000..345b377dfd
--- /dev/null
+++ b/railties/doc/guides/activerecord/active_record_basics.txt
@@ -0,0 +1,2 @@
+ActiveRecord Basics
+=================================
diff --git a/railties/doc/guides/activerecord/association_basics.txt b/railties/doc/guides/activerecord/association_basics.txt
index f9ec7a5f55..695b834652 100644
--- a/railties/doc/guides/activerecord/association_basics.txt
+++ b/railties/doc/guides/activerecord/association_basics.txt
@@ -354,8 +354,8 @@ In designing a data model, you will sometimes find a model that should have a re
[source, ruby]
-------------------------------------------------------
class Employee < ActiveRecord::Base
- has_many :subordinates, :class_name => :user, :foreign_key => "manager_id"
- belongs_to :manager, :class_name => :user
+ has_many :subordinates, :class_name => "User", :foreign_key => "manager_id"
+ belongs_to :manager, :class_name => "User"
end
-------------------------------------------------------
@@ -636,12 +636,12 @@ The +belongs_to+ association supports these options:
//
===== +:class_name+
-If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is patron, you'd set things up this way:
+If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is +Patron+, you'd set things up this way:
[source, ruby]
-------------------------------------------------------
class Order < ActiveRecord::Base
- belongs_to :customer, :class_name => :patron
+ belongs_to :customer, :class_name => "Patron"
end
-------------------------------------------------------
@@ -711,7 +711,7 @@ By convention, Rails guesses that the column used to hold the foreign key on thi
[source, ruby]
-------------------------------------------------------
class Order < ActiveRecord::Base
- belongs_to :customer, :class_name => :patron, :foreign_key => "patron_id"
+ belongs_to :customer, :class_name => "Patron", :foreign_key => "patron_id"
end
-------------------------------------------------------
@@ -863,7 +863,7 @@ In many situations, you can use the default behavior of +has_one+ without any cu
[source, ruby]
-------------------------------------------------------
class Supplier < ActiveRecord::Base
- has_one :account, :class_name => :billing, :dependent => :nullify
+ has_one :account, :class_name => "Billing", :dependent => :nullify
end
-------------------------------------------------------
@@ -895,12 +895,12 @@ Setting the +:as+ option indicates that this is a polymorphic association. Polym
===== +:class_name+
-If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is billing, you'd set things up this way:
+If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is Billing, you'd set things up this way:
[source, ruby]
-------------------------------------------------------
class Supplier < ActiveRecord::Base
- has_one :account, :class_name => :billing
+ has_one :account, :class_name => "Billing"
end
-------------------------------------------------------
@@ -1085,7 +1085,8 @@ The +_collection_.delete+ method removes one or more objects from the collection
@customer.orders.delete(@order1)
-------------------------------------------------------
-WARNING: The +_collection_.delete+ method will destroy the deleted object if they are declared as +belongs_to+ and are dependent on this model.
+WARNING: Objects will be in addition destroyed if they're associated with +:dependent => :destroy+, and deleted if they're associated with +:dependent => :delete_all+.
+
===== +_collection_=objects+
@@ -1205,12 +1206,12 @@ Setting the +:as+ option indicates that this is a polymorphic association, as di
===== +:class_name+
-If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is transactions, you'd set things up this way:
+If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is +Transaction+, you'd set things up this way:
[source, ruby]
-------------------------------------------------------
class Customer < ActiveRecord::Base
- has_many :orders, :class_name => :transaction
+ has_many :orders, :class_name => "Transaction"
end
-------------------------------------------------------
@@ -1221,7 +1222,7 @@ The +:conditions+ option lets you specify the conditions that the associated obj
[source, ruby]
-------------------------------------------------------
class Customer < ActiveRecord::Base
- has_many :confirmed_orders, :class_name => :orders, :conditions => "confirmed = 1"
+ has_many :confirmed_orders, :class_name => "Order", :conditions => "confirmed = 1"
end
-------------------------------------------------------
@@ -1230,7 +1231,7 @@ You can also set conditions via a hash:
[source, ruby]
-------------------------------------------------------
class Customer < ActiveRecord::Base
- has_many :confirmed_orders, :class_name => :orders, :conditions => { :confirmed => true }
+ has_many :confirmed_orders, :class_name => "Order", :conditions => { :confirmed => true }
end
-------------------------------------------------------
@@ -1321,7 +1322,7 @@ The +:limit+ option lets you restrict the total number of objects that will be f
[source, ruby]
-------------------------------------------------------
class Customer < ActiveRecord::Base
- has_many :recent_orders, :class_name => :orders, :order => "order_date DESC", :limit => 100
+ has_many :recent_orders, :class_name => "Order", :order => "order_date DESC", :limit => 100
end
-------------------------------------------------------
@@ -1591,19 +1592,19 @@ TIP: The +:foreign_key+ and +:association_foreign_key+ options are useful when s
[source, ruby]
-------------------------------------------------------
class User < ActiveRecord::Base
- has_and_belongs_to_many :friends, :class_name => :users,
+ has_and_belongs_to_many :friends, :class_name => "User",
:foreign_key => "this_user_id", :association_foreign_key => "other_user_id"
end
-------------------------------------------------------
===== +:class_name+
-If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is gadgets, you'd set things up this way:
+If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is +Gadget+, you'd set things up this way:
[source, ruby]
-------------------------------------------------------
class Parts < ActiveRecord::Base
- has_and_belongs_to_many :assemblies, :class_name => :gadgets
+ has_and_belongs_to_many :assemblies, :class_name => "Gadget"
end
-------------------------------------------------------
@@ -1654,7 +1655,7 @@ By convention, Rails guesses that the column in the join table used to hold the
[source, ruby]
-------------------------------------------------------
class User < ActiveRecord::Base
- has_and_belongs_to_many :friends, :class_name => :users,
+ has_and_belongs_to_many :friends, :class_name => "User",
:foreign_key => "this_user_id", :association_foreign_key => "other_user_id"
end
-------------------------------------------------------