Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 383 lines (343 sloc) 13.526 kB
e8550ee @jeremy Cherry-pick core extensions
jeremy authored
1 require 'active_support/core_ext/enumerable'
2
2b3cc24 @jeremy r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
jeremy authored
3 module ActiveRecord
4ad6103 @rizwanreza Adds title and basic description where needed.
rizwanreza authored
4 # = Active Record Attribute Methods
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
5 module AttributeMethods
4e50a35 @josh Break up DependencyModule's dual function of providing a "depend_on" …
josh authored
6 extend ActiveSupport::Concern
f8d3c72 @josh Extract generic attribute method generation to AMo
josh authored
7 include ActiveModel::AttributeMethods
a2875be @brynary Use DependencyModule for included hooks in ActiveRecord
brynary authored
8
17ad71e @jonleighton Let AttributeMethods do its own including etc
jonleighton authored
9 included do
10 include Read
11 include Write
12 include BeforeTypeCast
13 include Query
14 include PrimaryKey
15 include TimeZoneConversion
16 include Dirty
17 include Serialization
18 end
19
2b3cc24 @jeremy r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
jeremy authored
20 module ClassMethods
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
21 # Generates all the attribute related methods for columns in the database
22 # accessors, mutators and query methods.
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
23 def define_attribute_methods # :nodoc:
2c667f6 @jonleighton Fix race condition :bomb:
jonleighton authored
24 # Use a mutex; we don't want two thread simaltaneously trying to define
25 # attribute methods.
26 @attribute_methods_mutex.synchronize do
27 return if attribute_methods_generated?
28 superclass.define_attribute_methods unless self == base_class
29 super(column_names)
30 @attribute_methods_generated = true
31 end
24faddd @wildchild Move ActiveModel::AttributeMethods#attribute_methods_generated? to Ac…
wildchild authored
32 end
33
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
34 def attribute_methods_generated? # :nodoc:
f1eb98f @jonleighton Fix #4046.
jonleighton authored
35 @attribute_methods_generated ||= false
f1a534a @jonleighton Remove the need for type_cast_attribute.
jonleighton authored
36 end
37
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
38 def undefine_attribute_methods # :nodoc:
a1ee3ac @jonleighton Ensure attribute methods are included after all the AR stuff
jonleighton authored
39 super if attribute_methods_generated?
f1eb98f @jonleighton Fix #4046.
jonleighton authored
40 @attribute_methods_generated = false
e129c56 @josh Wrap up attribute method reset concerns in 'undefine_attribute_methods'
josh authored
41 end
42
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
43 # Raises a <tt>ActiveRecord::DangerousAttributeError</tt> exception when an
44 # \Active \Record method is defined in the model, otherwise +false+.
45 #
46 # class Person < ActiveRecord::Base
47 # def save
48 # 'already defined by Active Record'
49 # end
50 # end
51 #
52 # Person.instance_method_already_implemented?(:save)
53 # # => ActiveRecord::DangerousAttributeError: save is defined by ActiveRecord
54 #
55 # Person.instance_method_already_implemented?(:name)
56 # # => false
b31aa63 Allow column accessors to be created even if Kernel. or Object# metho…
Tobias Lütke authored
57 def instance_method_already_implemented?(method_name)
55da28d @jonleighton We don't need to build a set for DangerousAttributeError.
jonleighton authored
58 if dangerous_attribute_method?(method_name)
59 raise DangerousAttributeError, "#{method_name} is defined by ActiveRecord"
60 end
61
9e4c41c @jonleighton Remove ActiveRecord::Model
jonleighton authored
62 if superclass == Base
f1eb98f @jonleighton Fix #4046.
jonleighton authored
63 super
64 else
4d8ee28 @jonleighton Fix situation where id method didn't get defined causing postgres to …
jonleighton authored
65 # If B < A and A defines its own attribute method, then we don't want to overwrite that.
66 defined = method_defined_within?(method_name, superclass, superclass.generated_attribute_methods)
67 defined && !ActiveRecord::Base.method_defined?(method_name) || super
f1eb98f @jonleighton Fix #4046.
jonleighton authored
68 end
b31aa63 Allow column accessors to be created even if Kernel. or Object# metho…
Tobias Lütke authored
69 end
d916c62 @wycats eliminate alias_method_chain from ActiveRecord
wycats authored
70
55da28d @jonleighton We don't need to build a set for DangerousAttributeError.
jonleighton authored
71 # A method name is 'dangerous' if it is already defined by Active Record, but
72 # not by any ancestors. (So 'puts' is not dangerous but 'save' is.)
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
73 def dangerous_attribute_method?(name) # :nodoc:
f1eb98f @jonleighton Fix #4046.
jonleighton authored
74 method_defined_within?(name, Base)
75 end
55da28d @jonleighton We don't need to build a set for DangerousAttributeError.
jonleighton authored
76
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
77 def method_defined_within?(name, klass, sup = klass.superclass) # :nodoc:
f1eb98f @jonleighton Fix #4046.
jonleighton authored
78 if klass.method_defined?(name) || klass.private_method_defined?(name)
79 if sup.method_defined?(name) || sup.private_method_defined?(name)
80 klass.instance_method(name).owner != sup.instance_method(name).owner
81 else
82 true
83 end
84 else
85 false
86 end
d916c62 @wycats eliminate alias_method_chain from ActiveRecord
wycats authored
87 end
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
88
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
89 # Returns +true+ if +attribute+ is an attribute method and table exists,
90 # +false+ otherwise.
91 #
92 # class Person < ActiveRecord::Base
93 # end
94 #
95 # Person.attribute_method?('name') # => true
96 # Person.attribute_method?(:age=) # => true
97 # Person.attribute_method?(:nothing) # => false
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
98 def attribute_method?(attribute)
99 super || (table_exists? && column_names.include?(attribute.to_s.sub(/=$/, '')))
100 end
101
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
102 # Returns an array of column names as strings if it's not an abstract class and
103 # table exists. Otherwise it returns an empty array.
104 #
105 # class Person < ActiveRecord::Base
106 # end
107 #
108 # Person.attribute_names
109 # # => ["id", "created_at", "updated_at", "name", "age"]
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
110 def attribute_names
111 @attribute_names ||= if !abstract_class? && table_exists?
112 column_names
113 else
114 []
115 end
116 end
c30a0ce @paulgillard Modified ActiveRecord::AttributeMethods to allow classes to specify a…
paulgillard authored
117 end
64eecdd @josh whitespace
josh authored
118
ac687ed @jonleighton Let Ruby deal with method visibility.
jonleighton authored
119 # If we haven't generated any methods yet, generate them, then
120 # see if we've created the method we're looking for.
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
121 def method_missing(method, *args, &block) # :nodoc:
ac687ed @jonleighton Let Ruby deal with method visibility.
jonleighton authored
122 unless self.class.attribute_methods_generated?
5b801b5 @NZKoz Change the implementation of ActiveRecord's attribute reader and writ…
NZKoz authored
123 self.class.define_attribute_methods
ac687ed @jonleighton Let Ruby deal with method visibility.
jonleighton authored
124
125 if respond_to_without_attributes?(method)
126 send(method, *args, &block)
127 else
128 super
129 end
364a8f3 @jeremy No need to check for generated method, just redispatch
jeremy authored
130 else
131 super
5b801b5 @NZKoz Change the implementation of ActiveRecord's attribute reader and writ…
NZKoz authored
132 end
133 end
134
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
135 def attribute_missing(match, *args, &block) # :nodoc:
1a421ce @jonleighton Deprecate using method_missing for attributes that are columns.
jonleighton authored
136 if self.class.columns_hash[match.attr_name]
137 ActiveSupport::Deprecation.warn(
138 "The method `#{match.method_name}', matching the attribute `#{match.attr_name}' has " \
139 "dispatched through method_missing. This shouldn't happen, because `#{match.attr_name}' " \
140 "is a column of the table. If this error has happened through normal usage of Active " \
141 "Record (rather than through your own code or external libraries), please report it as " \
142 "a bug."
143 )
144 end
145
146 super
147 end
148
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
149 # A Person object with a name attribute can ask <tt>person.respond_to?(:name)</tt>,
150 # <tt>person.respond_to?(:name=)</tt>, and <tt>person.respond_to?(:name?)</tt>
151 # which will all return +true+. It also define the attribute methods if they have
152 # not been generated.
153 #
154 # class Person < ActiveRecord::Base
155 # end
156 #
157 # person = Person.new
158 # person.respond_to(:name) # => true
159 # person.respond_to(:name=) # => true
160 # person.respond_to(:name?) # => true
161 # person.respond_to('age') # => true
162 # person.respond_to('age=') # => true
163 # person.respond_to('age?') # => true
164 # person.respond_to(:nothing) # => false
6a283d5 @tenderlove match method signature of the superclass
tenderlove authored
165 def respond_to?(name, include_private = false)
e0e3adf @jeremy Cheaper attribute reads and respond_to?. Add underscore-prefixed meth…
jeremy authored
166 self.class.define_attribute_methods unless self.class.attribute_methods_generated?
5b801b5 @NZKoz Change the implementation of ActiveRecord's attribute reader and writ…
NZKoz authored
167 super
168 end
2b3cc24 @jeremy r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
jeremy authored
169
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
170 # Returns +true+ if the given attribute is in the attributes hash, otherwise +false+.
171 #
172 # class Person < ActiveRecord::Base
173 # end
174 #
175 # person = Person.new
176 # person.has_attribute?(:name) # => true
177 # person.has_attribute?('age') # => true
178 # person.has_attribute?(:nothing) # => false
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
179 def has_attribute?(attr_name)
180 @attributes.has_key?(attr_name.to_s)
181 end
182
183 # Returns an array of names for the attributes available on this object.
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
184 #
185 # class Person < ActiveRecord::Base
186 # end
187 #
188 # person = Person.new
189 # person.attribute_names
190 # # => ["id", "created_at", "updated_at", "name", "age"]
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
191 def attribute_names
192 @attributes.keys
193 end
194
195 # Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
196 #
197 # class Person < ActiveRecord::Base
198 # end
199 #
200 # person = Person.create(name: 'Francesco', age: 22)
201 # person.attributes
202 # # => {"id"=>3, "created_at"=>Sun, 21 Oct 2012 04:53:04, "updated_at"=>Sun, 21 Oct 2012 04:53:04, "name"=>"Francesco", "age"=>22}
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
203 def attributes
f9cfe9a @spastorino Use each_with_object instead of each here
spastorino authored
204 attribute_names.each_with_object({}) { |name, attrs|
205 attrs[name] = read_attribute(name)
206 }
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
207 end
208
209 # Returns an <tt>#inspect</tt>-like string for the value of the
210 # attribute +attr_name+. String attributes are truncated upto 50
211 # characters, and Date and Time attributes are returned in the
212 # <tt>:db</tt> format. Other attributes return the value of
213 # <tt>#inspect</tt> without modification.
214 #
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
215 # person = Person.create!(name: 'David Heinemeier Hansson ' * 3)
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
216 #
217 # person.attribute_for_inspect(:name)
bc3f960 improve AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
218 # # => "\"David Heinemeier Hansson David Heinemeier Hansson D...\""
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
219 #
220 # person.attribute_for_inspect(:created_at)
bc3f960 improve AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
221 # # => "\"2012-10-22 00:15:07\""
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
222 def attribute_for_inspect(attr_name)
223 value = read_attribute(attr_name)
224
225 if value.is_a?(String) && value.length > 50
226 "#{value[0..50]}...".inspect
227 elsif value.is_a?(Date) || value.is_a?(Time)
228 %("#{value.to_s(:db)}")
229 else
230 value.inspect
231 end
232 end
233
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
234 # Returns +true+ if the specified +attribute+ has been set by the user or by a
235 # database load and is neither +nil+ nor <tt>empty?</tt> (the latter only applies
236 # to objects that respond to <tt>empty?</tt>, most notably Strings). Otherwise, +false+.
bc3f960 improve AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
237 # Note that it always returns +true+ with boolean attributes.
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
238 #
bc3f960 improve AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
239 # class Task < ActiveRecord::Base
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
240 # end
241 #
bc3f960 improve AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
242 # person = Task.new(title: '', is_done: false)
243 # person.attribute_present?(:title) # => false
244 # person.attribute_present?(:is_done) # => true
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
245 # person.name = 'Francesco'
bc3f960 improve AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
246 # person.is_done = true
247 # person.attribute_present?(:title) # => true
248 # person.attribute_present?(:is_done) # => true
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
249 def attribute_present?(attribute)
250 value = read_attribute(attribute)
04aca25 @Jacobkg attribute_present? should return false for empty strings
Jacobkg authored
251 !value.nil? && !(value.respond_to?(:empty?) && value.empty?)
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
252 end
253
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
254 # Returns the column object for the named attribute. Returns +nil+ if the
255 # named attribute not exists.
256 #
257 # class Person < ActiveRecord::Base
258 # end
259 #
260 # person = Person.new
261 # person.column_for_attribute(:name) # the result depends on the ConnectionAdapter
262 # # => #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x007ff4ab083980 @name="name", @sql_type="varchar(255)", @null=true, ...>
263 #
264 # person.column_for_attribute(:nothing)
265 # # => nil
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
266 def column_for_attribute(name)
3e0ecde @tenderlove adding a comment for myself
tenderlove authored
267 # FIXME: should this return a null object for columns that don't exist?
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
268 self.class.columns_hash[name.to_s]
269 end
270
65df7b3 @jonleighton no need to define methods in included hook
jonleighton authored
271 # Returns the value of the attribute identified by <tt>attr_name</tt> after it has been typecast (for example,
3b0bb08 @vijaydev Merge branch 'master' of github.com:lifo/docrails
vijaydev authored
272 # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). It raises
273 # <tt>ActiveModel::MissingAttributeError</tt> if the identified attribute is missing.
274 #
275 # Alias for the <tt>read_attribute</tt> method.
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
276 #
277 # class Person < ActiveRecord::Base
10f6f90 AR::AttributeMethods#[] raises AM::AttributeMissingError for missing …
Francesco Rodriguez authored
278 # belongs_to :organization
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
279 # end
280 #
06e908c Fix AR::AttributeMethods#[] example [ci skip]
Francesco Rodriguez authored
281 # person = Person.new(name: 'Francesco', age: '22')
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
282 # person[:name] # => "Francesco"
283 # person[:age] # => 22
10f6f90 AR::AttributeMethods#[] raises AM::AttributeMissingError for missing …
Francesco Rodriguez authored
284 #
285 # person = Person.select('id').first
286 # person[:name] # => ActiveModel::MissingAttributeError: missing attribute: name
287 # person[:organization_id] # => ActiveModel::MissingAttributeError: missing attribute: organization_id
65df7b3 @jonleighton no need to define methods in included hook
jonleighton authored
288 def [](attr_name)
10f6f90 AR::AttributeMethods#[] raises AM::AttributeMissingError for missing …
Francesco Rodriguez authored
289 read_attribute(attr_name) { |n| missing_attribute(n, caller) }
65df7b3 @jonleighton no need to define methods in included hook
jonleighton authored
290 end
291
292 # Updates the attribute identified by <tt>attr_name</tt> with the specified +value+.
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
293 # (Alias for the protected <tt>write_attribute</tt> method).
294 #
295 # class Person < ActiveRecord::Base
296 # end
297 #
298 # person = Person.new
299 # person[:age] = '22'
300 # person[:age] # => 22
301 # person[:age] # => Fixnum
65df7b3 @jonleighton no need to define methods in included hook
jonleighton authored
302 def []=(attr_name, value)
303 write_attribute(attr_name, value)
304 end
305
f8d3c72 @josh Extract generic attribute method generation to AMo
josh authored
306 protected
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
307
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
308 def clone_attributes(reader_method = :read_attribute, attributes = {}) # :nodoc:
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
309 attribute_names.each do |name|
310 attributes[name] = clone_attribute_value(reader_method, name)
311 end
312 attributes
313 end
314
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
315 def clone_attribute_value(reader_method, attribute_name) # :nodoc:
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
316 value = send(reader_method, attribute_name)
317 value.duplicable? ? value.clone : value
318 rescue TypeError, NoMethodError
319 value
320 end
321
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
322 def arel_attributes_with_values_for_create(attribute_names) # :nodoc:
144e869 @jonleighton Support for partial inserts.
jonleighton authored
323 arel_attributes_with_values(attributes_for_create(attribute_names))
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
324 end
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
325
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
326 def arel_attributes_with_values_for_update(attribute_names) # :nodoc:
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
327 arel_attributes_with_values(attributes_for_update(attribute_names))
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
328 end
329
aceb4a5 update AR::AttributeMethods documentation [ci skip]
Francesco Rodriguez authored
330 def attribute_method?(attr_name) # :nodoc:
d7942d4 @lest handle id attribute in PrimaryKey module
lest authored
331 defined?(@attributes) && @attributes.include?(attr_name)
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
332 end
333
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
334 private
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
335
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
336 # Returns a Hash of the Arel::Attributes and attribute values that have been
337 # type casted for use in an Arel insert/update method.
338 def arel_attributes_with_values(attribute_names)
339 attrs = {}
340 arel_table = self.class.arel_table
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
341
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
342 attribute_names.each do |name|
343 attrs[arel_table[name]] = typecasted_attribute_value(name)
344 end
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
345 attrs
346 end
347
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
348 # Filters the primary keys and readonly attributes from the attribute names.
349 def attributes_for_update(attribute_names)
350 attribute_names.select do |name|
351 column_for_attribute(name) && !pk_attribute?(name) && !readonly_attribute?(name)
352 end
353 end
354
355 # Filters out the primary keys, from the attribute names, when the primary
356 # key is to be generated (e.g. the id attribute has no value).
144e869 @jonleighton Support for partial inserts.
jonleighton authored
357 def attributes_for_create(attribute_names)
358 attribute_names.select do |name|
359 column_for_attribute(name) && !(pk_attribute?(name) && id.nil?)
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
360 end
6024d53 @robinroestenburg Refactored method arel_attributes_values.
robinroestenburg authored
361 end
362
363 def readonly_attribute?(name)
364 self.class.readonly_attributes.include?(name)
365 end
366
a02d237 @robinroestenburg Removed flag attributes.
robinroestenburg authored
367 def pk_attribute?(name)
368 column_for_attribute(name).primary
6024d53 @robinroestenburg Refactored method arel_attributes_values.
robinroestenburg authored
369 end
370
371 def typecasted_attribute_value(name)
372 if self.class.serialized_attributes.include?(name)
373 @attributes[name].serialized_value
374 else
375 # FIXME: we need @attributes to be used consistently.
376 # If the values stored in @attributes were already typecasted, this code
377 # could be simplified
378 read_attribute(name)
379 end
ceb33f8 @jonleighton Split out most of the AR::Base code into separate modules :cake:
jonleighton authored
380 end
2b3cc24 @jeremy r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
jeremy authored
381 end
382 end
Something went wrong with that request. Please try again.