Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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