activerecord 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (106) hide show
  1. data/CHANGELOG +581 -0
  2. data/README +361 -0
  3. data/RUNNING_UNIT_TESTS +36 -0
  4. data/dev-utils/eval_debugger.rb +9 -0
  5. data/examples/associations.png +0 -0
  6. data/examples/associations.rb +87 -0
  7. data/examples/shared_setup.rb +15 -0
  8. data/examples/validation.rb +88 -0
  9. data/install.rb +60 -0
  10. data/lib/active_record.rb +48 -0
  11. data/lib/active_record/aggregations.rb +165 -0
  12. data/lib/active_record/associations.rb +536 -0
  13. data/lib/active_record/associations/association_collection.rb +70 -0
  14. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +46 -0
  15. data/lib/active_record/associations/has_many_association.rb +104 -0
  16. data/lib/active_record/base.rb +985 -0
  17. data/lib/active_record/callbacks.rb +337 -0
  18. data/lib/active_record/connection_adapters/abstract_adapter.rb +326 -0
  19. data/lib/active_record/connection_adapters/mysql_adapter.rb +131 -0
  20. data/lib/active_record/connection_adapters/postgresql_adapter.rb +177 -0
  21. data/lib/active_record/connection_adapters/sqlite_adapter.rb +107 -0
  22. data/lib/active_record/deprecated_associations.rb +70 -0
  23. data/lib/active_record/fixtures.rb +172 -0
  24. data/lib/active_record/observer.rb +71 -0
  25. data/lib/active_record/reflection.rb +126 -0
  26. data/lib/active_record/support/class_attribute_accessors.rb +43 -0
  27. data/lib/active_record/support/class_inheritable_attributes.rb +37 -0
  28. data/lib/active_record/support/clean_logger.rb +10 -0
  29. data/lib/active_record/support/inflector.rb +70 -0
  30. data/lib/active_record/transactions.rb +102 -0
  31. data/lib/active_record/validations.rb +205 -0
  32. data/lib/active_record/vendor/mysql.rb +1117 -0
  33. data/lib/active_record/vendor/simple.rb +702 -0
  34. data/lib/active_record/wrappers/yaml_wrapper.rb +15 -0
  35. data/lib/active_record/wrappings.rb +59 -0
  36. data/rakefile +122 -0
  37. data/test/abstract_unit.rb +16 -0
  38. data/test/aggregations_test.rb +34 -0
  39. data/test/all.sh +8 -0
  40. data/test/associations_test.rb +477 -0
  41. data/test/base_test.rb +513 -0
  42. data/test/class_inheritable_attributes_test.rb +33 -0
  43. data/test/connections/native_mysql/connection.rb +24 -0
  44. data/test/connections/native_postgresql/connection.rb +24 -0
  45. data/test/connections/native_sqlite/connection.rb +24 -0
  46. data/test/deprecated_associations_test.rb +336 -0
  47. data/test/finder_test.rb +67 -0
  48. data/test/fixtures/accounts/signals37 +3 -0
  49. data/test/fixtures/accounts/unknown +2 -0
  50. data/test/fixtures/auto_id.rb +4 -0
  51. data/test/fixtures/column_name.rb +3 -0
  52. data/test/fixtures/companies/first_client +6 -0
  53. data/test/fixtures/companies/first_firm +4 -0
  54. data/test/fixtures/companies/second_client +6 -0
  55. data/test/fixtures/company.rb +37 -0
  56. data/test/fixtures/company_in_module.rb +33 -0
  57. data/test/fixtures/course.rb +3 -0
  58. data/test/fixtures/courses/java +2 -0
  59. data/test/fixtures/courses/ruby +2 -0
  60. data/test/fixtures/customer.rb +30 -0
  61. data/test/fixtures/customers/david +6 -0
  62. data/test/fixtures/db_definitions/mysql.sql +96 -0
  63. data/test/fixtures/db_definitions/mysql2.sql +4 -0
  64. data/test/fixtures/db_definitions/postgresql.sql +113 -0
  65. data/test/fixtures/db_definitions/postgresql2.sql +4 -0
  66. data/test/fixtures/db_definitions/sqlite.sql +85 -0
  67. data/test/fixtures/db_definitions/sqlite2.sql +4 -0
  68. data/test/fixtures/default.rb +2 -0
  69. data/test/fixtures/developer.rb +8 -0
  70. data/test/fixtures/developers/david +2 -0
  71. data/test/fixtures/developers/jamis +2 -0
  72. data/test/fixtures/developers_projects/david_action_controller +2 -0
  73. data/test/fixtures/developers_projects/david_active_record +2 -0
  74. data/test/fixtures/developers_projects/jamis_active_record +2 -0
  75. data/test/fixtures/entrant.rb +3 -0
  76. data/test/fixtures/entrants/first +3 -0
  77. data/test/fixtures/entrants/second +3 -0
  78. data/test/fixtures/entrants/third +3 -0
  79. data/test/fixtures/fixture_database.sqlite +0 -0
  80. data/test/fixtures/fixture_database_2.sqlite +0 -0
  81. data/test/fixtures/movie.rb +5 -0
  82. data/test/fixtures/movies/first +2 -0
  83. data/test/fixtures/movies/second +2 -0
  84. data/test/fixtures/project.rb +3 -0
  85. data/test/fixtures/projects/action_controller +2 -0
  86. data/test/fixtures/projects/active_record +2 -0
  87. data/test/fixtures/reply.rb +21 -0
  88. data/test/fixtures/subscriber.rb +5 -0
  89. data/test/fixtures/subscribers/first +2 -0
  90. data/test/fixtures/subscribers/second +2 -0
  91. data/test/fixtures/topic.rb +20 -0
  92. data/test/fixtures/topics/first +9 -0
  93. data/test/fixtures/topics/second +8 -0
  94. data/test/fixtures_test.rb +20 -0
  95. data/test/inflector_test.rb +104 -0
  96. data/test/inheritance_test.rb +125 -0
  97. data/test/lifecycle_test.rb +110 -0
  98. data/test/modules_test.rb +21 -0
  99. data/test/multiple_db_test.rb +46 -0
  100. data/test/pk_test.rb +57 -0
  101. data/test/reflection_test.rb +78 -0
  102. data/test/thread_safety_test.rb +33 -0
  103. data/test/transactions_test.rb +83 -0
  104. data/test/unconnected_test.rb +24 -0
  105. data/test/validations_test.rb +126 -0
  106. metadata +166 -0
@@ -0,0 +1,581 @@
1
+ *1.0.0 (35)*
2
+
3
+ * Added OO-style associations methods [Florian Weber]. Examples:
4
+
5
+ Project#milestones_count => Project#milestones.size
6
+ Project#build_to_milestones => Project#milestones.build
7
+ Project#create_for_milestones => Project#milestones.create
8
+ Project#find_in_milestones => Project#milestones.find
9
+ Project#find_all_in_milestones => Project#milestones.find_all
10
+
11
+ * Added serialize as a new class method to control when text attributes should be YAMLized or not. This means that automated
12
+ serialization of hashes, arrays, and so on WILL NO LONGER HAPPEN (#10). You need to do something like this:
13
+
14
+ class User < ActiveRecord::Base
15
+ serialize :settings
16
+ end
17
+
18
+ This will assume that settings is a text column and will now YAMLize any object put in that attribute. You can also specify
19
+ an optional :class_name option that'll raise an exception if a serialized object is retrieved as a descendent of a class not in
20
+ the hierarchy. Example:
21
+
22
+ class User < ActiveRecord::Base
23
+ serialize :settings, :class_name => "Hash"
24
+ end
25
+
26
+ user = User.create("settings" => %w( one two three ))
27
+ User.find(user.id).settings # => raises SerializationTypeMismatch
28
+
29
+ * Added the option to connect to a different database for one model at a time. Just call establish_connection on the class
30
+ you want to have connected to another database than Base. This will automatically also connect decendents of that class
31
+ to the different database [Renald Buter].
32
+
33
+ * Added transactional protection for Base#save. Validations can now check for values knowing that it happens in a transaction and callbacks
34
+ can raise exceptions knowing that the save will be rolled back. [Suggested by Alexey Verkhovsky]
35
+
36
+ * Added column name quoting so reserved words, such as "references", can be used as column names [Ryan Platte]
37
+
38
+ * Added the possibility to chain the return of what happened inside a logged block [geech]:
39
+
40
+ This now works:
41
+ log { ... }.map { ... }
42
+
43
+ Instead of doing:
44
+ result = []
45
+ log { result = ... }
46
+ result.map { ... }
47
+
48
+ * Added "socket" option for the MySQL adapter, so you can change it to something else than "/tmp/mysql.sock" [Anna Liss Cruz]
49
+
50
+ * Added respond_to? answers for all the attribute methods. So if Person has a name attribute retrieved from the table schema,
51
+ person.respond_to? "name" will return true.
52
+
53
+ * Added Base.benchmark which can be used to aggregate logging and benchmark, so you can measure and represent multiple statements in a single block.
54
+ Usage (hides all the SQL calls for the individual actions and calculates total runtime for them all):
55
+
56
+ Project.benchmark("Creating project") do
57
+ project = Project.create("name" => "stuff")
58
+ project.create_manager("name" => "David")
59
+ project.milestones << Milestone.find_all
60
+ end
61
+
62
+ * Added logging of invalid SQL statements [Suggested by Daniel Von Fange]
63
+
64
+ * Added alias Errors#[] for Errors#on, so you can now say person.errors["name"] to retrieve the errors for name [Andreas Schwarz]
65
+
66
+ * Added RubyGems require attempt if sqlite-ruby is not available through regular methods.
67
+
68
+ * Added compatibility with 2.x series of sqlite-ruby drivers. [Jamis Buck]
69
+
70
+ * Added type safety for association assignments, so a ActiveRecord::AssociationTypeMismatch will be raised if you attempt to
71
+ assign an object that's not of the associated class. This cures the problem with nil giving id = 4 and fixnums giving id = 1 on
72
+ mistaken association assignments. [Reported by Andreas Schwarz]
73
+
74
+ * Added the option to keep many fixtures in one single YAML document [what-a-day]
75
+
76
+ * Added the class method "inheritance_column" that can be overwritten to return the name of an alternative column than "type" for storing
77
+ the type for inheritance hierarchies. [Dave Steinberg]
78
+
79
+ * Added [] and []= as an alternative way to access attributes when the regular methods have been overwritten [Dave Steinberg]
80
+
81
+ * Added the option to observer more than one class at the time by specifying observed_class as an array
82
+
83
+ * Added auto-id propagation support for tables with arbitrary primary keys that have autogenerated sequences associated with them
84
+ on PostgreSQL. [Dave Steinberg]
85
+
86
+ * Changed that integer and floats set to "" through attributes= remain as NULL. This was especially a problem for scaffolding and postgresql. (#49)
87
+
88
+ * Changed the MySQL Adapter to rely on MySQL for its defaults for socket, host, and port [Andreas Schwarz]
89
+
90
+ * Changed ActionControllerError to decent from StandardError instead of Exception. It can now be caught by a generic rescue.
91
+
92
+ * Changed class inheritable attributes to not use eval [Caio Chassot]
93
+
94
+ * Changed Errors#add to now use "invalid" as the default message instead of true, which means full_messages work with those [Marcel Molina Jr]
95
+
96
+ * Fixed spelling on Base#add_on_boundry_breaking to Base#add_on_boundary_breaking (old naming still works) [Marcel Molina Jr.]
97
+
98
+ * Fixed that entries in the has_and_belongs_to_many join table didn't get removed when an associated object was destroyed.
99
+
100
+ * Fixed unnecessary calls to SET AUTOCOMMIT=0/1 for MySQL adapter [Andreas Schwarz]
101
+
102
+ * Fixed PostgreSQL defaults are now handled gracefully [Dave Steinberg]
103
+
104
+ * Fixed increment/decrement_counter are now atomic updates [Andreas Schwarz]
105
+
106
+ * Fixed the problems the Inflector had turning Attachment into attuchments and Cases into Casis [radsaq/Florian Gross]
107
+
108
+ * Fixed that cloned records would point attribute references on the parent object [Andreas Schwarz]
109
+
110
+ * Fixed SQL for type call on inheritance hierarchies [Caio Chassot]
111
+
112
+ * Fixed bug with typed inheritance [Florian Weber]
113
+
114
+ * Fixed a bug where has_many collection_count wouldn't use the conditions specified for that association
115
+
116
+
117
+ *0.9.5*
118
+
119
+ * Expanded the table_name guessing rules immensely [Florian Green]. Documentation:
120
+
121
+ Guesses the table name (in forced lower-case) based on the name of the class in the inheritance hierarchy descending
122
+ directly from ActiveRecord. So if the hierarchy looks like: Reply < Message < ActiveRecord, then Message is used
123
+ to guess the table name from even when called on Reply. The guessing rules are as follows:
124
+ * Class name ends in "x", "ch" or "ss": "es" is appended, so a Search class becomes a searches table.
125
+ * Class name ends in "y" preceded by a consonant or "qu": The "y" is replaced with "ies",
126
+ so a Category class becomes a categories table.
127
+ * Class name ends in "fe": The "fe" is replaced with "ves", so a Wife class becomes a wives table.
128
+ * Class name ends in "lf" or "rf": The "f" is replaced with "ves", so a Half class becomes a halves table.
129
+ * Class name ends in "person": The "person" is replaced with "people", so a Salesperson class becomes a salespeople table.
130
+ * Class name ends in "man": The "man" is replaced with "men", so a Spokesman class becomes a spokesmen table.
131
+ * Class name ends in "sis": The "i" is replaced with an "e", so a Basis class becomes a bases table.
132
+ * Class name ends in "tum" or "ium": The "um" is replaced with an "a", so a Datum class becomes a data table.
133
+ * Class name ends in "child": The "child" is replaced with "children", so a NodeChild class becomes a node_children table.
134
+ * Class name ends in an "s": No additional characters are added or removed.
135
+ * Class name doesn't end in "s": An "s" is appended, so a Comment class becomes a comments table.
136
+ * Class name with word compositions: Compositions are underscored, so CreditCard class becomes a credit_cards table.
137
+ Additionally, the class-level table_name_prefix is prepended to the table_name and the table_name_suffix is appended.
138
+ So if you have "myapp_" as a prefix, the table name guess for an Account class becomes "myapp_accounts".
139
+
140
+ You can also overwrite this class method to allow for unguessable links, such as a Mouse class with a link to a
141
+ "mice" table. Example:
142
+
143
+ class Mouse < ActiveRecord::Base
144
+ def self.table_name() "mice" end
145
+ end
146
+
147
+ This conversion is now done through an external class called Inflector residing in lib/active_record/support/inflector.rb.
148
+
149
+ * Added find_all_in_collection to has_many defined collections. Works like this:
150
+
151
+ class Firm < ActiveRecord::Base
152
+ has_many :clients
153
+ end
154
+
155
+ firm.id # => 1
156
+ firm.find_all_in_clients "revenue > 1000" # SELECT * FROM clients WHERE firm_id = 1 AND revenue > 1000
157
+
158
+ [Requested by Dave Thomas]
159
+
160
+ * Fixed finders for inheritance hierarchies deeper than one level [Florian Weber]
161
+
162
+ * Added add_on_boundry_breaking to errors to accompany add_on_empty as a default validation method. It's used like this:
163
+
164
+ class Person < ActiveRecord::Base
165
+ protected
166
+ def validation
167
+ errors.add_on_boundry_breaking "password", 3..20
168
+ end
169
+ end
170
+
171
+ This will add an error to the tune of "is too short (min is 3 characters)" or "is too long (min is 20 characters)" if
172
+ the password is outside the boundry. The messages can be changed by passing a third and forth parameter as message strings.
173
+
174
+ * Implemented a clone method that works properly with AR. It returns a clone of the record that
175
+ hasn't been assigned an id yet and is treated as a new record.
176
+
177
+ * Allow for domain sockets in PostgreSQL by not assuming localhost when no host is specified [Scott Barron]
178
+
179
+ * Fixed that bignums are saved properly instead of attempted to be YAMLized [Andreas Schwartz]
180
+
181
+ * Fixed a bug in the GEM where the rdoc options weren't being passed according to spec [Chad Fowler]
182
+
183
+ * Fixed a bug with the exclusively_dependent option for has_many
184
+
185
+
186
+ *0.9.4*
187
+
188
+ * Correctly guesses the primary key when the class is inside a module [Dave Steinberg].
189
+
190
+ * Added [] and []= as alternatives to read_attribute and write_attribute [Dave Steinberg]
191
+
192
+ * has_and_belongs_to_many now accepts an :order key to determine in which order the collection is returned [radsaq].
193
+
194
+ * The ids passed to find and find_on_conditions are now automatically sanitized.
195
+
196
+ * Added escaping of plings in YAML content.
197
+
198
+ * Multi-parameter assigns where all the parameters are empty will now be set to nil instead of a new instance of their class.
199
+
200
+ * Proper type within an inheritance hierarchy is now ensured already at object initialization (instead of first at create)
201
+
202
+
203
+ *0.9.3*
204
+
205
+ * Fixed bug with using a different primary key name together with has_and_belongs_to_many [Investigation by Scott]
206
+
207
+ * Added :exclusively_dependent option to the has_many association macro. The doc reads:
208
+
209
+ If set to true all the associated object are deleted in one SQL statement without having their
210
+ before_destroy callback run. This should only be used on associations that depend solely on
211
+ this class and don't need to do any clean-up in before_destroy. The upside is that it's much
212
+ faster, especially if there's a counter_cache involved.
213
+
214
+ * Added :port key to connection options, so the PostgreSQL and MySQL adapters can connect to a database server
215
+ running on another port than the default.
216
+
217
+ * Converted the new natural singleton methods that prevented AR objects from being saved by PStore
218
+ (and hence be placed in a Rails session) to a module. [Florian Weber]
219
+
220
+ * Fixed the use of floats (was broken since 0.9.0+)
221
+
222
+ * Fixed PostgreSQL adapter so default values are displayed properly when used in conjunction with
223
+ Action Pack scaffolding.
224
+
225
+ * Fixed booleans support for PostgreSQL (use real true/false�on boolean fields instead of 0/1 on tinyints) [radsaq]
226
+
227
+
228
+ *0.9.2*
229
+
230
+ * Added static method for instantly updating a record
231
+
232
+ * Treat decimal and numeric as Ruby floats [Andreas Schwartz]
233
+
234
+ * Treat chars as Ruby strings (fixes problem for Action Pack form helpers too)
235
+
236
+ * Removed debugging output accidently left in (which would screw web applications)
237
+
238
+
239
+ *0.9.1*
240
+
241
+ * Added MIT license
242
+
243
+ * Added natural object-style assignment for has_and_belongs_to_many associations. Consider the following model:
244
+
245
+ class Event < ActiveRecord::Base
246
+ has_one_and_belongs_to_many :sponsors
247
+ end
248
+
249
+ class Sponsor < ActiveRecord::Base
250
+ has_one_and_belongs_to_many :sponsors
251
+ end
252
+
253
+ Earlier, you'd have to use synthetic methods for creating associations between two objects of the above class:
254
+
255
+ roskilde_festival.add_to_sponsors(carlsberg)
256
+ roskilde_festival.remove_from_sponsors(carlsberg)
257
+
258
+ nike.add_to_events(world_cup)
259
+ nike.remove_from_events(world_cup)
260
+
261
+ Now you can use regular array-styled methods:
262
+
263
+ roskilde_festival.sponsors << carlsberg
264
+ roskilde_festival.sponsors.delete(carlsberg)
265
+
266
+ nike.events << world_cup
267
+ nike.events.delete(world_cup)
268
+
269
+ * Added delete method for has_many associations. Using this will nullify an association between the has_many and the belonging
270
+ object by setting the foreign key to null. Consider this model:
271
+
272
+ class Post < ActiveRecord::Base
273
+ has_many :comments
274
+ end
275
+
276
+ class Comment < ActiveRecord::Base
277
+ belongs_to :post
278
+ end
279
+
280
+ You could do something like:
281
+
282
+ funny_comment.has_post? # => true
283
+ announcement.comments.delete(funny_comment)
284
+ funny_comment.has_post? # => false
285
+
286
+
287
+ *0.9.0*
288
+
289
+ * Active Record is now thread safe! (So you can use it with Cerise and WEBrick applications)
290
+ [Implementation idea by Michael Neumann, debugging assistance by Jamis Buck]
291
+
292
+ * Improved performance by roughly 400% on a basic test case of pulling 100 records and querying one attribute.
293
+ This brings the tax for using Active Record instead of "riding on the metal" (using MySQL-ruby C-driver directly) down to ~50%.
294
+ Done by doing lazy type conversions and caching column information on the class-level.
295
+
296
+ * Added callback objects and procs as options for implementing the target for callback macros.
297
+
298
+ * Added "counter_cache" option to belongs_to that automates the usage of increment_counter and decrement_counter. Consider:
299
+
300
+ class Post < ActiveRecord::Base
301
+ has_many :comments
302
+ end
303
+
304
+ class Comment < ActiveRecord::Base
305
+ belongs_to :post
306
+ end
307
+
308
+ Iterating over 100 posts like this:
309
+
310
+ <% for post in @posts %>
311
+ <%= post.title %> has <%= post.comments_count %> comments
312
+ <% end %>
313
+
314
+ Will generate 100 SQL count queries -- one for each call to post.comments_count. If you instead add a "comments_count" int column
315
+ to the posts table and rewrite the comments association macro with:
316
+
317
+ class Comment < ActiveRecord::Base
318
+ belongs_to :post, :counter_cache => true
319
+ end
320
+
321
+ Those 100 SQL count queries will be reduced to zero. Beware that counter caching is only appropriate for objects that begin life
322
+ with the object it's specified to belong with and is destroyed like that as well. Typically objects where you would also specify
323
+ :dependent => true. If your objects switch from one belonging to another (like a post that can be move from one category to another),
324
+ you'll have to manage the counter yourself.
325
+
326
+ * Added natural object-style assignment for has_one and belongs_to associations. Consider the following model:
327
+
328
+ class Project < ActiveRecord::Base
329
+ has_one :manager
330
+ end
331
+
332
+ class Manager < ActiveRecord::Base
333
+ belongs_to :project
334
+ end
335
+
336
+ Earlier, assignments would work like following regardless of which way the assignment told the best story:
337
+
338
+ active_record.manager_id = david.id
339
+
340
+ Now you can do it either from the belonging side:
341
+
342
+ david.project = active_record
343
+
344
+ ...or from the having side:
345
+
346
+ active_record.manager = david
347
+
348
+ If the assignment happens from the having side, the assigned object is automatically saved. So in the example above, the
349
+ project_id attribute on david would be set to the id of active_record, then david would be saved.
350
+
351
+ * Added natural object-style assignment for has_many associations [Florian Weber]. Consider the following model:
352
+
353
+ class Project < ActiveRecord::Base
354
+ has_many :milestones
355
+ end
356
+
357
+ class Milestone < ActiveRecord::Base
358
+ belongs_to :project
359
+ end
360
+
361
+ Earlier, assignments would work like following regardless of which way the assignment told the best story:
362
+
363
+ deadline.project_id = active_record.id
364
+
365
+ Now you can do it either from the belonging side:
366
+
367
+ deadline.project = active_record
368
+
369
+ ...or from the having side:
370
+
371
+ active_record.milestones << deadline
372
+
373
+ The milestone is automatically saved with the new foreign key.
374
+
375
+ * API CHANGE: Attributes for text (or blob or similar) columns will now have unknown classes stored using YAML instead of using
376
+ to_s. (Known classes that won't be yamelized are: String, NilClass, TrueClass, FalseClass, Fixnum, Date, and Time).
377
+ Likewise, data pulled out of text-based attributes will be attempted converged using Yaml if they have the "--- " header.
378
+ This was primarily done to be enable the storage of hashes and arrays without wrapping them in aggregations, so now you can do:
379
+
380
+ user = User.find(1)
381
+ user.preferences = { "background" => "black", "display" => large }
382
+ user.save
383
+
384
+ User.find(1).preferences # => { "background" => "black", "display" => large }
385
+
386
+ Please note that this method should only be used when you don't care about representing the object in proper columns in
387
+ the database. A money object consisting of an amount and a currency is still a much better fit for a value object done through
388
+ aggregations than this new option.
389
+
390
+ * POSSIBLE CODE BREAKAGE: As a consequence of the lazy type conversions, it's a bad idea to reference the @attributes hash
391
+ directly (it always was, but now it's paramount that you don't). If you do, you won't get the type conversion. So to implement
392
+ new accessors for existing attributes, use read_attribute(attr_name) and write_attribute(attr_name, value) instead. Like this:
393
+
394
+ class Song < ActiveRecord::Base
395
+ # Uses an integer of seconds to hold the length of the song
396
+
397
+ def length=(minutes)
398
+ write_attribute("length", minutes * 60)
399
+ end
400
+
401
+ def length
402
+ read_attribute("length") / 60
403
+ end
404
+ end
405
+
406
+ The clever kid will notice that this opens a door to sidestep the automated type conversion by using @attributes directly.
407
+ This is not recommended as read/write_attribute may be granted additional responsibilities in the future, but if you think
408
+ you know what you're doing and aren't afraid of future consequences, this is an option.
409
+
410
+ * Applied a few minor bug fixes reported by Daniel Von Fange.
411
+
412
+
413
+ *0.8.4*
414
+
415
+ _Reflection_
416
+
417
+ * Added ActiveRecord::Reflection with a bunch of methods and classes for reflecting in aggregations and associations.
418
+
419
+ * Added Base.columns and Base.content_columns which returns arrays of column description (type, default, etc) objects.
420
+
421
+ * Added Base#attribute_names which returns an array of names for the attributes available on the object.
422
+
423
+ * Added Base#column_for_attribute(name) which returns the column description object for the named attribute.
424
+
425
+
426
+ _Misc_
427
+
428
+ * Added multi-parameter assignment:
429
+
430
+ # Instantiate objects for all attribute classes that needs more than one constructor parameter. This is done
431
+ # by calling new on the column type or aggregation type (through composed_of) object with these parameters.
432
+ # So having the pairs written_on(1) = "2004", written_on(2) = "6", written_on(3) = "24", will instantiate
433
+ # written_on (a date type) with Date.new("2004", "6", "24"). You can also specify a typecast character in the
434
+ # parenteses to have the parameters typecasted before they're used in the constructor. Use i for Fixnum, f for Float,
435
+ # s for String, and a for Array.
436
+
437
+ This is incredibly useful for assigning dates from HTML drop-downs of month, year, and day.
438
+
439
+ * Fixed bug with custom primary key column name and Base.find on multiple parameters.
440
+
441
+ * Fixed bug with dependent option on has_one associations if there was no associated object.
442
+
443
+
444
+ *0.8.3*
445
+
446
+ _Transactions_
447
+
448
+ * Added transactional protection for destroy (important for the new :dependent option) [Suggested by Carl Youngblood]
449
+
450
+ * Fixed so transactions are ignored on MyISAM tables for MySQL (use InnoDB to get transactions)
451
+
452
+ * Changed transactions so only exceptions will cause a rollback, not returned false.
453
+
454
+
455
+ _Mapping_
456
+
457
+ * Added support for non-integer primary keys [Aredridel/earlier work by Michael Neumann]
458
+
459
+ User.find "jdoe"
460
+ Product.find "PDKEY-INT-12"
461
+
462
+ * Added option to specify naming method for primary key column. ActiveRecord::Base.primary_key_prefix_type can either
463
+ be set to nil, :table_name, or :table_name_with_underscore. :table_name will assume that Product class has a primary key
464
+ of "productid" and :table_name_with_underscore will assume "product_id". The default nil will just give "id".
465
+
466
+ * Added an overwriteable primary_key method that'll instruct AR to the name of the
467
+ id column [Aredridele/earlier work by Guan Yang]
468
+
469
+ class Project < ActiveRecord::Base
470
+ def self.primary_key() "project_id" end
471
+ end
472
+
473
+ * Fixed that Active Records can safely associate inside and out of modules.
474
+
475
+ class MyApplication::Account < ActiveRecord::Base
476
+ has_many :clients # will look for MyApplication::Client
477
+ has_many :interests, :class_name => "Business::Interest" # will look for Business::Interest
478
+ end
479
+
480
+ * Fixed that Active Records can safely live inside modules [Aredridel]
481
+
482
+ class MyApplication::Account < ActiveRecord::Base
483
+ end
484
+
485
+
486
+ _Misc_
487
+
488
+ * Added freeze call to value object assignments to ensure they remain immutable [Spotted by Gavin Sinclair]
489
+
490
+ * Changed interface for specifying observed class in observers. Was OBSERVED_CLASS constant, now is
491
+ observed_class() class method. This is more consistant with things like self.table_name(). Works like this:
492
+
493
+ class AuditObserver < ActiveRecord::Observer
494
+ def self.observed_class() Account end
495
+ def after_update(account)
496
+ AuditTrail.new(account, "UPDATED")
497
+ end
498
+ end
499
+
500
+ [Suggested by Gavin Sinclair]
501
+
502
+ * Create new Active Record objects by setting the attributes through a block. Like this:
503
+
504
+ person = Person.new do |p|
505
+ p.name = 'Freddy'
506
+ p.age = 19
507
+ end
508
+
509
+ [Suggested by Gavin Sinclair]
510
+
511
+
512
+ *0.8.2*
513
+
514
+ * Added inheritable callback queues that can ensure that certain callback methods or inline fragments are
515
+ run throughout the entire inheritance hierarchy. Regardless of whether a descendent overwrites the callback
516
+ method:
517
+
518
+ class Topic < ActiveRecord::Base
519
+ before_destroy :destroy_author, 'puts "I'm an inline fragment"'
520
+ end
521
+
522
+ Learn more in link:classes/ActiveRecord/Callbacks.html
523
+
524
+ * Added :dependent option to has_many and has_one, which will automatically destroy associated objects when
525
+ the holder is destroyed:
526
+
527
+ class Album < ActiveRecord::Base
528
+ has_many :tracks, :dependent => true
529
+ end
530
+
531
+ All the associated tracks are destroyed when the album is.
532
+
533
+ * Added Base.create as a factory that'll create, save, and return a new object in one step.
534
+
535
+ * Automatically convert strings in config hashes to symbols for the _connection methods. This allows you
536
+ to pass the argument hashes directly from yaml. (Luke)
537
+
538
+ * Fixed the install.rb to include simple.rb [Spotted by Kevin Bullock]
539
+
540
+ * Modified block syntax to better follow our code standards outlined in
541
+ http://www.rubyonrails.org/CodingStandards
542
+
543
+
544
+ *0.8.1*
545
+
546
+ * Added object-level transactions [Thanks to Austin Ziegler for Transaction::Simple]
547
+
548
+ * Changed adapter-specific connection methods to use centralized ActiveRecord::Base.establish_connection,
549
+ which is parametized through a config hash with symbol keys instead of a regular parameter list.
550
+ This will allow for database connections to be opened in a more generic fashion. (Luke)
551
+
552
+ NOTE: This requires all *_connections to be updated! Read more in:
553
+ http://ar.rubyonrails.org/classes/ActiveRecord/Base.html#M000081
554
+
555
+ * Fixed SQLite adapter so objects fetched from has_and_belongs_to_many have proper attributes
556
+ (t.name is now name). [Spotted by Garrett Rooney]
557
+
558
+ * Fixed SQLite adapter so dates are returned as Date objects, not Time objects [Spotted by Gavin Sinclair]
559
+
560
+ * Fixed requirement of date class, so date conversions are succesful regardless of whether you
561
+ manually require date or not.
562
+
563
+
564
+ *0.8.0*
565
+
566
+ * Added transactions
567
+
568
+ * Changed Base.find to also accept either a list (1, 5, 6) or an array of ids ([5, 7])
569
+ as parameter and then return an array of objects instead of just an object
570
+
571
+ * Fixed method has_collection? for has_and_belongs_to_many macro to behave as a
572
+ collection, not an association
573
+
574
+ * Fixed SQLite adapter so empty or nil values in columns of datetime, date, or time type
575
+ aren't treated as current time [Spotted by Gavin Sinclair]
576
+
577
+
578
+ *0.7.6*
579
+
580
+ * Fixed the install.rb to create the lib/active_record/support directory [Spotted by Gavin Sinclair]
581
+ * Fixed that has_association? would always return true [Spotted by Daniel Von Fange]