Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 324 lines (318 sloc) 14.782 kB
db045db @dhh Initial
dhh authored
1 require 'yaml'
aabf909 @jeremy Correct reader method generation for primary key attribute: handle ca…
jeremy authored
2 require 'set'
a15e02d @josevalim Unify benchmark APIs.
josevalim authored
3 require 'active_support/benchmarkable'
f5d720f @jeremy Opt in to Dependencies
jeremy authored
4 require 'active_support/dependencies'
033e0a0 @josevalim ActiveRecord and ActionPack now use the new descendants implementation.
josevalim authored
5 require 'active_support/descendants_tracker'
5f222c5 @jeremy Remove 'core' fluff. Hookable ActiveSupport.load_all!
jeremy authored
6 require 'active_support/time'
e8550ee @jeremy Cherry-pick core extensions
jeremy authored
7 require 'active_support/core_ext/class/attribute_accessors'
8 require 'active_support/core_ext/class/delegating_attributes'
9 require 'active_support/core_ext/array/extract_options'
10 require 'active_support/core_ext/hash/deep_merge'
11 require 'active_support/core_ext/hash/slice'
12 require 'active_support/core_ext/string/behavior'
89978f1 @fxn moves Object#singleton_class to Kernel#singleton_class to match Ruby …
fxn authored
13 require 'active_support/core_ext/kernel/singleton_class'
4a8c880 @fxn refactors AR::Base#reset_table_name
fxn authored
14 require 'active_support/core_ext/module/introspection'
105f9b8 @fxn adds missing requires for Object#duplicable?
fxn authored
15 require 'active_support/core_ext/object/duplicable'
89b5b31 @diminish7 Added STI support to init and building associations
diminish7 authored
16 require 'active_support/core_ext/class/subclasses'
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored
17 require 'arel'
18 require 'active_record/errors'
6788db8 @josevalim Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing f…
josevalim authored
19 require 'active_record/log_subscriber'
cfeac38 @fxn implements a much faster auto EXPLAIN, closes #3843 [José Valim & Xav…
fxn authored
20 require 'active_record/explain_subscriber'
db045db @dhh Initial
dhh authored
21
22 module ActiveRecord #:nodoc:
606088d @eac Mass assignment security refactoring
eac authored
23 # = Active Record
4ad6103 @rizwanreza Adds title and basic description where needed.
rizwanreza authored
24 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
25 # Active Record objects don't specify their attributes directly, but rather infer them from
26 # the table definition with which they're linked. Adding, removing, and changing attributes
27 # and their type is done directly in the database. Any change is instantly reflected in the
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
28 # Active Record objects. The mapping that binds a given Active Record class to a certain
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
29 # database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.
30 #
20333be @tilsammans fix broken relative links [#5415 state:committed]
tilsammans authored
31 # See the mapping rules in table_name and the full example in link:files/activerecord/README_rdoc.html for more insight.
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
32 #
db045db @dhh Initial
dhh authored
33 # == Creation
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
34 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
35 # Active Records accept constructor parameters either in a hash or as a block. The hash
36 # method is especially useful when you're receiving the data from somewhere else, like an
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
37 # HTTP request. It works like this:
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
38 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
39 # user = User.new(name: "David", occupation: "Code Artist")
db045db @dhh Initial
dhh authored
40 # user.name # => "David"
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
41 #
db045db @dhh Initial
dhh authored
42 # You can also use block initialization:
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
43 #
db045db @dhh Initial
dhh authored
44 # user = User.new do |u|
45 # u.name = "David"
46 # u.occupation = "Code Artist"
47 # end
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
48 #
db045db @dhh Initial
dhh authored
49 # And of course you can just create a bare object and specify the attributes after the fact:
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
50 #
db045db @dhh Initial
dhh authored
51 # user = User.new
52 # user.name = "David"
53 # user.occupation = "Code Artist"
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
54 #
db045db @dhh Initial
dhh authored
55 # == Conditions
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
56 #
c5ec16e @dhh Added simple hash conditions to find that'll just convert hash to an …
dhh authored
57 # Conditions can either be specified as a string, array, or hash representing the WHERE-part of an SQL statement.
9e18380 @fxn Revert "Explicitly included hashes in sentence regarding SQL-injectio…
fxn authored
58 # The array form is to be used when the condition input is tainted and requires sanitization. The string form can
59 # be used for statements that don't involve tainted data. The hash form works much like the array form, except
60 # only equality and range is possible. Examples:
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
61 #
48052d7 @jeremy to_xml fixes, features, and speedup. Closes #4989.
jeremy authored
62 # class User < ActiveRecord::Base
db045db @dhh Initial
dhh authored
63 # def self.authenticate_unsafely(user_name, password)
2c27e3d @lifo Some doc updates reflecting the new query API
lifo authored
64 # where("user_name = '#{user_name}' AND password = '#{password}'").first
db045db @dhh Initial
dhh authored
65 # end
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
66 #
db045db @dhh Initial
dhh authored
67 # def self.authenticate_safely(user_name, password)
2c27e3d @lifo Some doc updates reflecting the new query API
lifo authored
68 # where("user_name = ? AND password = ?", user_name, password).first
db045db @dhh Initial
dhh authored
69 # end
c5ec16e @dhh Added simple hash conditions to find that'll just convert hash to an …
dhh authored
70 #
71 # def self.authenticate_safely_simply(user_name, password)
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
72 # where(user_name: user_name, password: password).first
c5ec16e @dhh Added simple hash conditions to find that'll just convert hash to an …
dhh authored
73 # end
db045db @dhh Initial
dhh authored
74 # end
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
75 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
76 # The <tt>authenticate_unsafely</tt> method inserts the parameters directly into the query
77 # and is thus susceptible to SQL-injection attacks if the <tt>user_name</tt> and +password+
04d37b0 @smartinez87 Remove extra whitespaces
smartinez87 authored
78 # parameters come directly from an HTTP request. The <tt>authenticate_safely</tt> and
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
79 # <tt>authenticate_safely_simply</tt> both will sanitize the <tt>user_name</tt> and +password+
80 # before inserting them in the query, which will ensure that an attacker can't escape the
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
81 # query and fake the login (or worse).
2575b3b @dhh Added extra words of caution for guarding against SQL-injection attacks
dhh authored
82 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
83 # When using multiple parameters in the conditions, it can easily become hard to read exactly
84 # what the fourth or fifth question mark is supposed to represent. In those cases, you can
85 # resort to named bind variables instead. That's done by replacing the question marks with
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
86 # symbols and supplying a hash with values for the matching symbol keys:
5cd38ca @dhh Added documentation about named bind variables
dhh authored
87 #
2c27e3d @lifo Some doc updates reflecting the new query API
lifo authored
88 # Company.where(
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
89 # "id = :id AND name = :name AND division = :division AND created_at > :accounting_date",
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
90 # { id: 3, name: "37signals", division: "First", accounting_date: '2005-01-01' }
2c27e3d @lifo Some doc updates reflecting the new query API
lifo authored
91 # ).first
5cd38ca @dhh Added documentation about named bind variables
dhh authored
92 #
c5ec16e @dhh Added simple hash conditions to find that'll just convert hash to an …
dhh authored
93 # Similarly, a simple hash without a statement will generate conditions based on equality with the SQL AND
94 # operator. For instance:
95 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
96 # Student.where(first_name: "Harvey", status: 1)
2c27e3d @lifo Some doc updates reflecting the new query API
lifo authored
97 # Student.where(params[:student])
c5ec16e @dhh Added simple hash conditions to find that'll just convert hash to an …
dhh authored
98 #
2876707 @jeremy Pass a range in :conditions to use the SQL BETWEEN operator. Closes #…
jeremy authored
99 # A range may be used in the hash to use the SQL BETWEEN operator:
100 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
101 # Student.where(grade: 9..12)
c5ec16e @dhh Added simple hash conditions to find that'll just convert hash to an …
dhh authored
102 #
aa4af60 @lifo Improve documentation.
lifo authored
103 # An array may be used in the hash to use the SQL IN operator:
104 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
105 # Student.where(grade: [9,11,12])
aa4af60 @lifo Improve documentation.
lifo authored
106 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
107 # When joining tables, nested hashes or keys written in the form 'table_name.column_name'
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
108 # can be used to qualify the table name of a particular condition. For instance:
e033b5d @lifo Merge docrails
lifo authored
109 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
110 # Student.joins(:schools).where(schools: { category: 'public' })
e552fe1 change activerecord query conditions example to avoid 'type' as colum…
Steve Bourne authored
111 # Student.joins(:schools).where('schools.category' => 'public' )
e033b5d @lifo Merge docrails
lifo authored
112 #
db045db @dhh Initial
dhh authored
113 # == Overwriting default accessors
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
114 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
115 # All column values are automatically available through basic accessors on the Active Record
116 # object, but sometimes you want to specialize this behavior. This can be done by overwriting
117 # the default accessors (using the same name as the attribute) and calling
118 # <tt>read_attribute(attr_name)</tt> and <tt>write_attribute(attr_name, value)</tt> to actually
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
119 # change things.
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
120 #
db045db @dhh Initial
dhh authored
121 # class Song < ActiveRecord::Base
122 # # Uses an integer of seconds to hold the length of the song
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
123 #
db045db @dhh Initial
dhh authored
124 # def length=(minutes)
64092de @fxn Improve documentation coverage and markup
fxn authored
125 # write_attribute(:length, minutes.to_i * 60)
db045db @dhh Initial
dhh authored
126 # end
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
127 #
db045db @dhh Initial
dhh authored
128 # def length
0591c53 @dhh Made the dynamic finders use the new find API and updated the example…
dhh authored
129 # read_attribute(:length) / 60
db045db @dhh Initial
dhh authored
130 # end
131 # end
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
132 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
133 # You can alternatively use <tt>self[:attribute]=(value)</tt> and <tt>self[:attribute]</tt>
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
134 # instead of <tt>write_attribute(:attribute, value)</tt> and <tt>read_attribute(:attribute)</tt>.
0591c53 @dhh Made the dynamic finders use the new find API and updated the example…
dhh authored
135 #
e4d845e Document automatically generated predicate methods for attributes. Cl…
Marcel Molina authored
136 # == Attribute query methods
137 #
138 # In addition to the basic accessors, query methods are also automatically available on the Active Record object.
139 # Query methods allow you to test whether an attribute value is present.
7367325 @jeremy Document Active Record exceptions. Closes #10444.
jeremy authored
140 #
e4d845e Document automatically generated predicate methods for attributes. Cl…
Marcel Molina authored
141 # For example, an Active Record User with the <tt>name</tt> attribute has a <tt>name?</tt> method that you can call
142 # to determine whether the user has a name:
143 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
144 # user = User.new(name: "David")
e4d845e Document automatically generated predicate methods for attributes. Cl…
Marcel Molina authored
145 # user.name? # => true
146 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
147 # anonymous = User.new(name: "")
e4d845e Document automatically generated predicate methods for attributes. Cl…
Marcel Molina authored
148 # anonymous.name? # => false
149 #
2948910 Misc doc fixes (typos/grammar/etc.). Closes #2430.
Marcel Molina authored
150 # == Accessing attributes before they have been typecasted
4eab375 @dhh Finished polishing API docs
dhh authored
151 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
152 # Sometimes you want to be able to read the raw attribute data without having the column-determined
153 # typecast run its course first. That can be done by using the <tt><attribute>_before_type_cast</tt>
154 # accessors that all attributes have. For example, if your Account model has a <tt>balance</tt> attribute,
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
155 # you can call <tt>account.balance_before_type_cast</tt> or <tt>account.id_before_type_cast</tt>.
4eab375 @dhh Finished polishing API docs
dhh authored
156 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
157 # This is especially useful in validation situations where the user might supply a string for an
158 # integer field and you want to display the original string back in an error message. Accessing the
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
159 # attribute normally would typecast the string to 0, which isn't what you want.
4eab375 @dhh Finished polishing API docs
dhh authored
160 #
ac8fd7d @dhh Added dynamic attribute-based finders as a cleaner way of getting obj…
dhh authored
161 # == Dynamic attribute-based finders
162 #
04cda18 @rubys Prefer find_by over dynamic finders in rdoc
rubys authored
163 # Dynamic attribute-based finders are a mildly deprecated way of getting (and/or creating) objects
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
164 # by simple queries without turning to SQL. They work by appending the name of an attribute
7bb34b1 @tbaba Remove useless number sign
tbaba authored
165 # to <tt>find_by_</tt> like <tt>Person.find_by_user_name</tt>.
04cda18 @rubys Prefer find_by over dynamic finders in rdoc
rubys authored
166 # Instead of writing <tt>Person.find_by(user_name: user_name)</tt>, you can use
44717a9 @amatsuda find_last_by is deprecated in AR 4
amatsuda authored
167 # <tt>Person.find_by_user_name(user_name)</tt>.
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
168 #
56efdbc Document exclamation point on dynamic finders
Florent Guilleux authored
169 # It's possible to add an exclamation point (!) on the end of the dynamic finders to get them to raise an
0d5a6f6 @jonleighton In 1efd88283ef68d912df215125951a87526768a51, ConnectionAdapters was p…
jonleighton authored
170 # <tt>ActiveRecord::RecordNotFound</tt> error if they do not return any records,
56efdbc Document exclamation point on dynamic finders
Florent Guilleux authored
171 # like <tt>Person.find_by_last_name!</tt>.
172 #
d3eacf9 @neerajdotname Adding to AR::Base documentation about dynamically scopeded_by query
neerajdotname authored
173 # It's also possible to use multiple attributes in the same find by separating them with "_and_".
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
174 #
04cda18 @rubys Prefer find_by over dynamic finders in rdoc
rubys authored
175 # Person.find_by(user_name: user_name, password: password)
2acb5e3 @fxn removes unrealistic example (authentication plus gender?), that it is…
fxn authored
176 # Person.find_by_user_name_and_password(user_name, password) # with dynamic finder
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
177 #
d3eacf9 @neerajdotname Adding to AR::Base documentation about dynamically scopeded_by query
neerajdotname authored
178 # It's even possible to call these dynamic finder methods on relations and named scopes.
2c27e3d @lifo Some doc updates reflecting the new query API
lifo authored
179 #
ad82753 @amatsuda find_all_by is deprecated in AR 4
amatsuda authored
180 # Payment.order("created_on").find_by_amount(50)
959f362 @dhh Added find_all style to the new dynamic finders
dhh authored
181 #
098fa94 @dhh Fixed documentation snafus #575, #576, #577, #585
dhh authored
182 # == Saving arrays, hashes, and other non-mappable objects in text columns
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
183 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
184 # Active Record can serialize any object in text columns using YAML. To do so, you must
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
185 # specify this with a call to the class method +serialize+.
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
186 # This makes it possible to store arrays, hashes, and other non-mappable objects without doing
187 # any additional work.
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
188 #
db045db @dhh Initial
dhh authored
189 # class User < ActiveRecord::Base
190 # serialize :preferences
191 # end
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
192 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
193 # user = User.create(preferences: { "background" => "black", "display" => large })
db045db @dhh Initial
dhh authored
194 # User.find(user.id).preferences # => { "background" => "black", "display" => large }
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
195 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
196 # You can also specify a class option as the second parameter that'll raise an exception
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
197 # if a serialized object is retrieved as a descendant of a class not in the hierarchy.
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
198 #
db045db @dhh Initial
dhh authored
199 # class User < ActiveRecord::Base
66f44e6 @dhh Updated documentation for serialize
dhh authored
200 # serialize :preferences, Hash
db045db @dhh Initial
dhh authored
201 # end
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
202 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
203 # user = User.create(preferences: %w( one two three ))
db045db @dhh Initial
dhh authored
204 # User.find(user.id).preferences # raises SerializationTypeMismatch
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
205 #
351331f @guillermo Make serialized columns with explicit object_type return a new instan…
guillermo authored
206 # When you specify a class option, the default value for that attribute will be a new
207 # instance of that class.
208 #
209 # class User < ActiveRecord::Base
210 # serialize :preferences, OpenStruct
211 # end
212 #
213 # user = User.new
214 # user.preferences.theme_color = "red"
215 #
216 #
db045db @dhh Initial
dhh authored
217 # == Single table inheritance
218 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
219 # Active Record allows inheritance by storing the name of the class in a column that by
220 # default is named "type" (can be changed by overwriting <tt>Base.inheritance_column</tt>).
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
221 # This means that an inheritance looking like this:
db045db @dhh Initial
dhh authored
222 #
223 # class Company < ActiveRecord::Base; end
224 # class Firm < Company; end
225 # class Client < Company; end
226 # class PriorityClient < Client; end
227 #
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
228 # When you do <tt>Firm.create(name: "37signals")</tt>, this record will be saved in
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
229 # the companies table with type = "Firm". You can then fetch this row again using
3c58018 @AvnerCohen 1.9 hash syntax changes
AvnerCohen authored
230 # <tt>Company.where(name: '37signals').first</tt> and it will return a Firm object.
db045db @dhh Initial
dhh authored
231 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
232 # If you don't have a type column defined in your table, single-table inheritance won't
233 # be triggered. In that case, it'll work just like normal subclasses with no special magic
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
234 # for differentiating between them or reloading the right type with find.
f033833 @dhh Improving documentation...
dhh authored
235 #
db045db @dhh Initial
dhh authored
236 # Note, all the attributes for all the cases are kept in the same table. Read more:
237 # http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
238 #
db045db @dhh Initial
dhh authored
239 # == Connection to multiple databases in different models
240 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
241 # Connections are usually created through ActiveRecord::Base.establish_connection and retrieved
242 # by ActiveRecord::Base.connection. All classes inheriting from ActiveRecord::Base will use this
243 # connection. But you can also set a class-specific connection. For example, if Course is an
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
244 # ActiveRecord::Base, but resides in a different database, you can just say <tt>Course.establish_connection</tt>
98dc582 @lifo Merge docrails.
lifo authored
245 # and Course and all of its subclasses will use this connection instead.
db045db @dhh Initial
dhh authored
246 #
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
247 # This feature is implemented by keeping a connection pool in ActiveRecord::Base that is
248 # a Hash indexed by the class. If a connection is requested, the retrieve_connection method
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
249 # will go up the class-hierarchy until a connection is found in the connection pool.
db045db @dhh Initial
dhh authored
250 #
251 # == Exceptions
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
252 #
dc4eec1 @lifo Merge docrails:
lifo authored
253 # * ActiveRecordError - Generic error class and superclass of all other errors raised by Active Record.
254 # * AdapterNotSpecified - The configuration hash used in <tt>establish_connection</tt> didn't include an
db045db @dhh Initial
dhh authored
255 # <tt>:adapter</tt> key.
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
256 # * AdapterNotFound - The <tt>:adapter</tt> key used in <tt>establish_connection</tt> specified a
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
257 # non-existent adapter
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
258 # (or a bad spelling of an existing one).
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
259 # * AssociationTypeMismatch - The object assigned to the association wasn't of the type
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
260 # specified in the association definition.
620cc9a @shime add ActiveRecord::RecordInvalid to exceptions
shime authored
261 # * AttributeAssignmentError - An error occurred while doing a mass assignment through the
262 # <tt>attributes=</tt> method.
263 # You can inspect the +attribute+ property of the exception object to determine which attribute
264 # triggered the error.
cf9664a @vijaydev fix markup error [ci skip]
vijaydev authored
265 # * ConnectionNotEstablished - No connection has been established. Use <tt>establish_connection</tt>
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
266 # before querying.
dc4eec1 @lifo Merge docrails:
lifo authored
267 # * MultiparameterAssignmentErrors - Collection of errors that occurred during a mass assignment using the
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
268 # <tt>attributes=</tt> method. The +errors+ property of this exception contains an array of
b8d9d9c @neerajdotname updating documentation to ensure line does not exceed 100 columns
neerajdotname authored
269 # AttributeAssignmentError
d2fefbe @dhh Added MultiparameterAssignmentErrors and AttributeAssignmentError exc…
dhh authored
270 # objects that should be inspected to determine which attributes triggered the errors.
0c9e7b6 @vijaydev more edits [ci skip]
vijaydev authored
271 # * RecordInvalid - raised by save! and create! when the record is invalid.
620cc9a @shime add ActiveRecord::RecordInvalid to exceptions
shime authored
272 # * RecordNotFound - No record responded to the +find+ method. Either the row with the given ID doesn't exist
273 # or the row didn't meet the additional restrictions. Some +find+ calls do not raise this exception to signal
274 # nothing was found, please check its documentation for further details.
275 # * SerializationTypeMismatch - The serialized object wasn't of the class specified as the second parameter.
276 # * StatementInvalid - The database server rejected the SQL statement. The precise error is added in the message.
5707027 @dhh Added better exception error when unknown column types are used with …
dhh authored
277 #
6e39c9e @jeremy r1614@asus: jeremy | 2005-07-03 08:01:08 -0700
jeremy authored
278 # *Note*: The attributes listed are class-level attributes (accessible from both the class and instance level).
dc4eec1 @lifo Merge docrails:
lifo authored
279 # So it's possible to assign a logger to the class through <tt>Base.logger=</tt> which will then be used by all
db045db @dhh Initial
dhh authored
280 # instances in the current object space.
281 class Base
9e4c41c @jonleighton Remove ActiveRecord::Model
jonleighton authored
282 extend ActiveModel::Naming
283
284 extend ActiveSupport::Benchmarkable
285 extend ActiveSupport::DescendantsTracker
286
287 extend ConnectionHandling
288 extend QueryCache::ClassMethods
289 extend Querying
290 extend Translation
291 extend DynamicMatchers
292 extend Explain
293
294 include Persistence
295 include ReadonlyAttributes
296 include ModelSchema
297 include Inheritance
298 include Scoping
299 include Sanitization
300 include AttributeAssignment
301 include ActiveModel::Conversion
302 include Integration
303 include Validations
304 include CounterCache
305 include Locking::Optimistic
306 include Locking::Pessimistic
307 include AttributeMethods
308 include Callbacks
309 include Timestamp
310 include Associations
311 include ActiveModel::SecurePassword
312 include AutosaveAssociation
313 include NestedAttributes
314 include Aggregations
315 include Transactions
316 include Reflection
317 include Serialization
318 include Store
319 include Core
7254d23 @josh Autoload ActiveRecord files
josh authored
320 end
4ed1563 @jeremy Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."
jeremy authored
321
9e4c41c @jonleighton Remove ActiveRecord::Model
jonleighton authored
322 ActiveSupport.run_load_hooks(:active_record, Base)
323 end
Something went wrong with that request. Please try again.