activerecord 3.0.0.beta4 → 3.0.0.rc
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.
- data/CHANGELOG +267 -254
- data/README.rdoc +222 -0
- data/examples/performance.rb +9 -9
- data/lib/active_record/aggregations.rb +3 -4
- data/lib/active_record/association_preload.rb +15 -10
- data/lib/active_record/associations.rb +54 -37
- data/lib/active_record/associations/association_collection.rb +43 -17
- data/lib/active_record/associations/association_proxy.rb +2 -0
- data/lib/active_record/associations/belongs_to_association.rb +1 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +22 -7
- data/lib/active_record/associations/has_many_association.rb +6 -1
- data/lib/active_record/associations/has_many_through_association.rb +1 -0
- data/lib/active_record/associations/has_one_association.rb +1 -0
- data/lib/active_record/associations/has_one_through_association.rb +1 -0
- data/lib/active_record/associations/through_association_scope.rb +3 -2
- data/lib/active_record/attribute_methods.rb +1 -0
- data/lib/active_record/autosave_association.rb +4 -6
- data/lib/active_record/base.rb +106 -240
- data/lib/active_record/callbacks.rb +4 -25
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +22 -29
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +2 -8
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +10 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +56 -7
- data/lib/active_record/connection_adapters/abstract_adapter.rb +10 -18
- data/lib/active_record/connection_adapters/mysql_adapter.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +65 -69
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +19 -6
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +20 -46
- data/lib/active_record/counter_cache.rb +14 -4
- data/lib/active_record/dynamic_finder_match.rb +9 -0
- data/lib/active_record/dynamic_scope_match.rb +7 -0
- data/lib/active_record/errors.rb +3 -0
- data/lib/active_record/fixtures.rb +5 -6
- data/lib/active_record/locale/en.yml +1 -1
- data/lib/active_record/locking/optimistic.rb +1 -0
- data/lib/active_record/log_subscriber.rb +48 -0
- data/lib/active_record/migration.rb +64 -37
- data/lib/active_record/named_scope.rb +33 -19
- data/lib/active_record/nested_attributes.rb +17 -13
- data/lib/active_record/observer.rb +13 -6
- data/lib/active_record/persistence.rb +55 -22
- data/lib/active_record/query_cache.rb +1 -0
- data/lib/active_record/railtie.rb +14 -8
- data/lib/active_record/railties/controller_runtime.rb +2 -2
- data/lib/active_record/railties/databases.rake +63 -33
- data/lib/active_record/reflection.rb +46 -28
- data/lib/active_record/relation.rb +38 -24
- data/lib/active_record/relation/finder_methods.rb +5 -5
- data/lib/active_record/relation/predicate_builder.rb +2 -4
- data/lib/active_record/relation/query_methods.rb +134 -115
- data/lib/active_record/relation/spawn_methods.rb +1 -1
- data/lib/active_record/schema.rb +2 -0
- data/lib/active_record/schema_dumper.rb +15 -12
- data/lib/active_record/serialization.rb +2 -0
- data/lib/active_record/session_store.rb +93 -79
- data/lib/active_record/test_case.rb +3 -0
- data/lib/active_record/timestamp.rb +49 -29
- data/lib/active_record/transactions.rb +5 -2
- data/lib/active_record/validations.rb +5 -2
- data/lib/active_record/validations/associated.rb +1 -1
- data/lib/active_record/validations/uniqueness.rb +1 -1
- data/lib/active_record/version.rb +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb +12 -6
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
- metadata +27 -14
- data/README +0 -351
- data/lib/active_record/railties/log_subscriber.rb +0 -32
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
*Rails 3.0.0 [release candidate] (July 26th, 2010)*
|
2
|
+
|
3
|
+
* Changed update_attribute to not run callbacks and update the record directly in the database [Neeraj Singh]
|
4
|
+
|
5
|
+
* Add scoping and unscoped as the syntax to replace the old with_scope and with_exclusive_scope [José Valim]
|
6
|
+
|
7
|
+
* New rake task, db:migrate:status, displays status of migrations #4947 [Kevin Skoglund]
|
8
|
+
|
9
|
+
* select and order for ActiveRecord now always concatenate nested calls. Use reorder if you want the original order to be overwritten [Santiago Pastorino]
|
10
|
+
|
11
|
+
* PostgreSQL: ensure the database time zone matches Ruby's time zone #4895 [Aaron Patterson]
|
12
|
+
|
13
|
+
|
1
14
|
*Rails 3.0.0 [beta 4] (June 8th, 2010)*
|
2
15
|
|
3
16
|
* Fixed that ActiveRecord::Base.compute_type would swallow NoMethodError #4751 [Andrew Bloomgarden, Andrew White]
|
@@ -304,7 +317,7 @@
|
|
304
317
|
|
305
318
|
* Add first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
|
306
319
|
|
307
|
-
* Added SQL escaping for :limit and :offset #288 [Aaron Bedra, Steven Bristol, Jonathan Wiess]
|
320
|
+
* Added SQL escaping for :limit and :offset #288 [Aaron Bedra, Steven Bristol, Jonathan Wiess]
|
308
321
|
|
309
322
|
* Added first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
|
310
323
|
|
@@ -615,7 +628,7 @@ so newlines etc are escaped #10385 [Norbert Crombach]
|
|
615
628
|
|
616
629
|
* Ensure that mysql quotes table names with database names correctly. Closes #9911 [crayz]
|
617
630
|
|
618
|
-
"foo.bar" => "`foo`.`bar`"
|
631
|
+
"foo.bar" => "`foo`.`bar`"
|
619
632
|
|
620
633
|
* Complete the assimilation of Sexy Migrations from ErrFree [Chris Wanstrath, PJ Hyett]
|
621
634
|
http://errtheblog.com/post/2381
|
@@ -750,7 +763,7 @@ single-table inheritance. #3833, #9886 [Gabriel Gironda, rramdas, François Bea
|
|
750
763
|
|
751
764
|
# Ensure that has_many :through associations use a count query instead of loading the target when #size is called. Closes #8800 [Pratik Naik]
|
752
765
|
|
753
|
-
* Added :unless clause to validations #8003 [monki]. Example:
|
766
|
+
* Added :unless clause to validations #8003 [monki]. Example:
|
754
767
|
|
755
768
|
def using_open_id?
|
756
769
|
!identity_url.blank?
|
@@ -770,7 +783,7 @@ single-table inheritance. #3833, #9886 [Gabriel Gironda, rramdas, François Bea
|
|
770
783
|
|
771
784
|
OLD
|
772
785
|
belongs_to :visitor, :class_name => 'User' # => inferred foreign_key is user_id
|
773
|
-
|
786
|
+
|
774
787
|
NEW
|
775
788
|
belongs_to :visitor, :class_name => 'User' # => inferred foreign_key is visitor_id
|
776
789
|
|
@@ -876,9 +889,9 @@ single-table inheritance. #3833, #9886 [Gabriel Gironda, rramdas, François Bea
|
|
876
889
|
t.column "created_at", :datetime
|
877
890
|
t.column "updated_at", :datetime
|
878
891
|
end
|
879
|
-
|
892
|
+
|
880
893
|
...can now be written as:
|
881
|
-
|
894
|
+
|
882
895
|
create_table :products do |t|
|
883
896
|
t.integer :shop_id, :creator_id
|
884
897
|
t.string :name, :value, :default => "Untitled"
|
@@ -954,7 +967,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
954
967
|
|
955
968
|
* Reworked David's query cache to be available as Model.cache {...}. For the duration of the block no select query should be run more then once. Any inserts/deletes/executes will flush the whole cache however [Tobias Lütke]
|
956
969
|
Task.cache { Task.find(1); Task.find(1) } #=> 1 query
|
957
|
-
|
970
|
+
|
958
971
|
* When dealing with SQLite3, use the table_info pragma helper, so that the bindings can do some translation for when sqlite3 breaks incompatibly between point releases. [Jamis Buck]
|
959
972
|
|
960
973
|
* Oracle: fix lob and text default handling. #7344 [gfriedrich, Michael Schoen]
|
@@ -1223,7 +1236,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1223
1236
|
|
1224
1237
|
* Cache nil results for has_one associations so multiple calls don't call the database. Closes #5757. [Michael Schoen]
|
1225
1238
|
|
1226
|
-
* Add documentation for how to disable timestamps on a per model basis. Closes #5684. [matt@mattmargolis.net Marcel Molina Jr.]
|
1239
|
+
* Add documentation for how to disable timestamps on a per model basis. Closes #5684. [matt@mattmargolis.net Marcel Molina Jr.]
|
1227
1240
|
|
1228
1241
|
* Don't save has_one associations unnecessarily. #5735 [Jonathan Viney]
|
1229
1242
|
|
@@ -1243,8 +1256,8 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1243
1256
|
|
1244
1257
|
* Added support for conditions on Base.exists? #5689 [Josh Peek]. Examples:
|
1245
1258
|
|
1246
|
-
assert (Topic.exists?(:author_name => "David"))
|
1247
|
-
assert (Topic.exists?(:author_name => "Mary", :approved => true))
|
1259
|
+
assert (Topic.exists?(:author_name => "David"))
|
1260
|
+
assert (Topic.exists?(:author_name => "Mary", :approved => true))
|
1248
1261
|
assert (Topic.exists?(["parent_id = ?", 1]))
|
1249
1262
|
|
1250
1263
|
* Schema dumper quotes date :default values. [Dave Thomas]
|
@@ -1322,14 +1335,14 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1322
1335
|
|
1323
1336
|
* Added simple hash conditions to find that'll just convert hash to an AND-based condition string #5143 [Hampton Catlin]. Example:
|
1324
1337
|
|
1325
|
-
Person.find(:all, :conditions => { :last_name => "Catlin", :status => 1 }, :limit => 2)
|
1338
|
+
Person.find(:all, :conditions => { :last_name => "Catlin", :status => 1 }, :limit => 2)
|
1326
1339
|
|
1327
1340
|
...is the same as:
|
1328
1341
|
|
1329
1342
|
Person.find(:all, :conditions => [ "last_name = ? and status = ?", "Catlin", 1 ], :limit => 2)
|
1330
|
-
|
1343
|
+
|
1331
1344
|
This makes it easier to pass in the options from a form or otherwise outside.
|
1332
|
-
|
1345
|
+
|
1333
1346
|
|
1334
1347
|
* Fixed issues with BLOB limits, charsets, and booleans for Firebird #5194, #5191, #5189 [kennethkunz@gmail.com]
|
1335
1348
|
|
@@ -1357,7 +1370,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1357
1370
|
|
1358
1371
|
* Fix the has_and_belongs_to_many #create doesn't populate the join for new records. Closes #3692 [Josh Susser]
|
1359
1372
|
|
1360
|
-
* Provide Association Extensions access to the instance that the association is being accessed from.
|
1373
|
+
* Provide Association Extensions access to the instance that the association is being accessed from.
|
1361
1374
|
Closes #4433 [Josh Susser]
|
1362
1375
|
|
1363
1376
|
* Update OpenBase adaterp's maintainer's email address. Closes #5176. [Derrick Spell]
|
@@ -1376,7 +1389,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1376
1389
|
|
1377
1390
|
* Call Inflector#demodulize on the class name when eagerly including an STI model. Closes #5077 [info@loobmedia.com]
|
1378
1391
|
|
1379
|
-
* Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk]
|
1392
|
+
* Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk]
|
1380
1393
|
|
1381
1394
|
* PostgreSQL: migrations support :limit with :integer columns by mapping limit < 4 to smallint, > 4 to bigint, and anything else to integer. #2900 [keegan@thebasement.org]
|
1382
1395
|
|
@@ -1386,7 +1399,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1386
1399
|
|
1387
1400
|
* Ensure that StringIO is always available for the Schema dumper. [Marcel Molina Jr.]
|
1388
1401
|
|
1389
|
-
* Allow AR::Base#to_xml to include methods too. Closes #4921. [johan@textdrive.com]
|
1402
|
+
* Allow AR::Base#to_xml to include methods too. Closes #4921. [johan@textdrive.com]
|
1390
1403
|
|
1391
1404
|
* Replace superfluous name_to_class_name variant with camelize. [Marcel Molina Jr.]
|
1392
1405
|
|
@@ -1396,7 +1409,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1396
1409
|
|
1397
1410
|
* Remove duplicate fixture entry in comments.yml. Closes #4923. [Blair Zajac <blair@orcaware.com>]
|
1398
1411
|
|
1399
|
-
* Update FrontBase adapter to check binding version. Closes #4920. [mlaster@metavillage.com]
|
1412
|
+
* Update FrontBase adapter to check binding version. Closes #4920. [mlaster@metavillage.com]
|
1400
1413
|
|
1401
1414
|
* New Frontbase connections don't start in auto-commit mode. Closes #4922. [mlaster@metavillage.com]
|
1402
1415
|
|
@@ -1408,9 +1421,9 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1408
1421
|
|
1409
1422
|
* Add warning about the proper way to validate the presence of a foreign key. Closes #4147. [Francois Beausoleil <francois.beausoleil@gmail.com>]
|
1410
1423
|
|
1411
|
-
* Fix syntax error in documentation. Closes #4679. [Mislav Marohnić]
|
1424
|
+
* Fix syntax error in documentation. Closes #4679. [Mislav Marohnić]
|
1412
1425
|
|
1413
|
-
* Add Oracle support for CLOB inserts. Closes #4748. [schoenm@earthlink.net sandra.metz@duke.edu]
|
1426
|
+
* Add Oracle support for CLOB inserts. Closes #4748. [schoenm@earthlink.net sandra.metz@duke.edu]
|
1414
1427
|
|
1415
1428
|
* Various fixes for sqlserver_adapter (odbc statement finishing, ado schema dumper, drop index). Closes #4831. [kajism@yahoo.com]
|
1416
1429
|
|
@@ -1461,7 +1474,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1461
1474
|
|
1462
1475
|
*1.15.3* (March 12th, 2007)
|
1463
1476
|
|
1464
|
-
* Allow a polymorphic :source for has_many :through associations. Closes #7143 [protocool]
|
1477
|
+
* Allow a polymorphic :source for has_many :through associations. Closes #7143 [protocool]
|
1465
1478
|
|
1466
1479
|
* Consistently quote primary key column names. #7763 [toolmantim]
|
1467
1480
|
|
@@ -1700,8 +1713,8 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1700
1713
|
|
1701
1714
|
* Added support for conditions on Base.exists? #5689 [Josh Peek]. Examples:
|
1702
1715
|
|
1703
|
-
assert (Topic.exists?(:author_name => "David"))
|
1704
|
-
assert (Topic.exists?(:author_name => "Mary", :approved => true))
|
1716
|
+
assert (Topic.exists?(:author_name => "David"))
|
1717
|
+
assert (Topic.exists?(:author_name => "Mary", :approved => true))
|
1705
1718
|
assert (Topic.exists?(["parent_id = ?", 1]))
|
1706
1719
|
|
1707
1720
|
* Schema dumper quotes date :default values. [Dave Thomas]
|
@@ -1775,7 +1788,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1775
1788
|
|
1776
1789
|
* Added simple hash conditions to find that'll just convert hash to an AND-based condition string #5143 [Hampton Catlin]. Example:
|
1777
1790
|
|
1778
|
-
Person.find(:all, :conditions => { :last_name => "Catlin", :status => 1 }, :limit => 2)
|
1791
|
+
Person.find(:all, :conditions => { :last_name => "Catlin", :status => 1 }, :limit => 2)
|
1779
1792
|
|
1780
1793
|
...is the same as:
|
1781
1794
|
|
@@ -1810,7 +1823,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1810
1823
|
|
1811
1824
|
* Fix the has_and_belongs_to_many #create doesn't populate the join for new records. Closes #3692 [Josh Susser]
|
1812
1825
|
|
1813
|
-
* Provide Association Extensions access to the instance that the association is being accessed from.
|
1826
|
+
* Provide Association Extensions access to the instance that the association is being accessed from.
|
1814
1827
|
Closes #4433 [Josh Susser]
|
1815
1828
|
|
1816
1829
|
* Update OpenBase adaterp's maintainer's email address. Closes #5176. [Derrick Spell]
|
@@ -1829,7 +1842,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1829
1842
|
|
1830
1843
|
* Call Inflector#demodulize on the class name when eagerly including an STI model. Closes #5077 [info@loobmedia.com]
|
1831
1844
|
|
1832
|
-
* Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk]
|
1845
|
+
* Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk]
|
1833
1846
|
|
1834
1847
|
* PostgreSQL: migrations support :limit with :integer columns by mapping limit < 4 to smallint, > 4 to bigint, and anything else to integer. #2900 [keegan@thebasement.org]
|
1835
1848
|
|
@@ -1839,7 +1852,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1839
1852
|
|
1840
1853
|
* Ensure that StringIO is always available for the Schema dumper. [Marcel Molina Jr.]
|
1841
1854
|
|
1842
|
-
* Allow AR::Base#to_xml to include methods too. Closes #4921. [johan@textdrive.com]
|
1855
|
+
* Allow AR::Base#to_xml to include methods too. Closes #4921. [johan@textdrive.com]
|
1843
1856
|
|
1844
1857
|
* Remove duplicate fixture entry in comments.yml. Closes #4923. [Blair Zajac <blair@orcaware.com>]
|
1845
1858
|
|
@@ -1849,9 +1862,9 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1849
1862
|
|
1850
1863
|
* Add warning about the proper way to validate the presence of a foreign key. Closes #4147. [Francois Beausoleil <francois.beausoleil@gmail.com>]
|
1851
1864
|
|
1852
|
-
* Fix syntax error in documentation. Closes #4679. [Mislav Marohnić]
|
1865
|
+
* Fix syntax error in documentation. Closes #4679. [Mislav Marohnić]
|
1853
1866
|
|
1854
|
-
* Add Oracle support for CLOB inserts. Closes #4748. [schoenm@earthlink.net sandra.metz@duke.edu]
|
1867
|
+
* Add Oracle support for CLOB inserts. Closes #4748. [schoenm@earthlink.net sandra.metz@duke.edu]
|
1855
1868
|
|
1856
1869
|
* Various fixes for sqlserver_adapter (odbc statement finishing, ado schema dumper, drop index). Closes #4831. [kajism@yahoo.com]
|
1857
1870
|
|
@@ -1899,7 +1912,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
1899
1912
|
|
1900
1913
|
* Add warning about the proper way to validate the presence of a foreign key. #4147 [Francois Beausoleil <francois.beausoleil@gmail.com>]
|
1901
1914
|
|
1902
|
-
* Fix syntax error in documentation. #4679 [Mislav Marohnić]
|
1915
|
+
* Fix syntax error in documentation. #4679 [Mislav Marohnić]
|
1903
1916
|
|
1904
1917
|
* Update inconsistent migrations documentation. #4683 [machomagna@gmail.com]
|
1905
1918
|
|
@@ -2195,7 +2208,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
2195
2208
|
<id type="integer">1</id>
|
2196
2209
|
<credit-limit type="integer">50</credit-limit>
|
2197
2210
|
</account>
|
2198
|
-
</firm>
|
2211
|
+
</firm>
|
2199
2212
|
|
2200
2213
|
* Allow :counter_cache to take a column name for custom counter cache columns [Jamis Buck]
|
2201
2214
|
|
@@ -2385,17 +2398,17 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
|
|
2385
2398
|
|
2386
2399
|
* Fixed that saving a model with multiple habtm associations would only save the first one. #3244 [yanowitz-rubyonrails@quantumfoam.org, Florian Weber]
|
2387
2400
|
|
2388
|
-
* Fix change_column to work with PostgreSQL 7.x and 8.x. #3141 [wejn@box.cz, Rick Olson, Scott Barron]
|
2401
|
+
* Fix change_column to work with PostgreSQL 7.x and 8.x. #3141 [wejn@box.cz, Rick Olson, Scott Barron]
|
2389
2402
|
|
2390
|
-
* removed :piggyback in favor of just allowing :select on :through associations. [Tobias Lütke]
|
2403
|
+
* removed :piggyback in favor of just allowing :select on :through associations. [Tobias Lütke]
|
2391
2404
|
|
2392
|
-
* made method missing delegation to class methods on relation target work on :through associations. [Tobias Lütke]
|
2405
|
+
* made method missing delegation to class methods on relation target work on :through associations. [Tobias Lütke]
|
2393
2406
|
|
2394
|
-
* made .find() work on :through relations. [Tobias Lütke]
|
2407
|
+
* made .find() work on :through relations. [Tobias Lütke]
|
2395
2408
|
|
2396
2409
|
* Fix typo in association docs. #3296. [Blair Zajac]
|
2397
2410
|
|
2398
|
-
* Fixed :through relations when using STI inherited classes would use the inherited class's name as foreign key on the join model [Tobias Lütke]
|
2411
|
+
* Fixed :through relations when using STI inherited classes would use the inherited class's name as foreign key on the join model [Tobias Lütke]
|
2399
2412
|
|
2400
2413
|
*1.13.2* (December 13th, 2005)
|
2401
2414
|
|
@@ -2658,7 +2671,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
2658
2671
|
|
2659
2672
|
* YAML fixtures support ordered hashes for fixtures with foreign key dependencies in the same table. #1896 [purestorm@ggnore.net]
|
2660
2673
|
|
2661
|
-
* :dependent now accepts :nullify option. Sets the foreign key of the related objects to NULL instead of deleting them. #2015 [Robby Russell <robby@planetargon.com>]
|
2674
|
+
* :dependent now accepts :nullify option. Sets the foreign key of the related objects to NULL instead of deleting them. #2015 [Robby Russell <robby@planetargon.com>]
|
2662
2675
|
|
2663
2676
|
* Introduce read-only records. If you call object.readonly! then it will mark the object as read-only and raise ReadOnlyRecord if you call object.save. object.readonly? reports whether the object is read-only. Passing :readonly => true to any finder method will mark returned records as read-only. The :joins option now implies :readonly, so if you use this option, saving the same record will now fail. Use find_by_sql to work around.
|
2664
2677
|
|
@@ -2813,7 +2826,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
2813
2826
|
def self.search(q)
|
2814
2827
|
find(:all, :conditions => ["body = ?", q])
|
2815
2828
|
end
|
2816
|
-
end
|
2829
|
+
end
|
2817
2830
|
|
2818
2831
|
class Post < AR:B
|
2819
2832
|
has_many :comments
|
@@ -2872,7 +2885,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
2872
2885
|
def evaluate_velocity(developer)
|
2873
2886
|
...
|
2874
2887
|
end
|
2875
|
-
end
|
2888
|
+
end
|
2876
2889
|
|
2877
2890
|
..raising an exception will cause the object not to be added (or removed, with before_remove).
|
2878
2891
|
|
@@ -2908,10 +2921,10 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
2908
2921
|
...should instead be:
|
2909
2922
|
|
2910
2923
|
Developer.find(
|
2911
|
-
:all,
|
2912
|
-
:joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
2924
|
+
:all,
|
2925
|
+
:joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
2913
2926
|
:conditions => 'project_id=1'
|
2914
|
-
)
|
2927
|
+
)
|
2915
2928
|
|
2916
2929
|
* Fixed that validations didn't respecting custom setting for too_short, too_long messages #1437 [Marcel Molina Jr.]
|
2917
2930
|
|
@@ -2948,7 +2961,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
2948
2961
|
|
2949
2962
|
* Return PostgreSQL columns in the order they were declared #1374 [perlguy@gmail.com]
|
2950
2963
|
|
2951
|
-
* Allow before/after update hooks to work on models using optimistic locking
|
2964
|
+
* Allow before/after update hooks to work on models using optimistic locking
|
2952
2965
|
|
2953
2966
|
* Eager loading of dependent has_one associations won't delete the association #1212
|
2954
2967
|
|
@@ -3128,10 +3141,10 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3128
3141
|
|
3129
3142
|
* Added adapter independent limit clause as a two-element array with the first being the limit, the second being the offset #795 [Sam Stephenson]. Example:
|
3130
3143
|
|
3131
|
-
Developer.find_all nil, 'id ASC', 5 # return the first five developers
|
3144
|
+
Developer.find_all nil, 'id ASC', 5 # return the first five developers
|
3132
3145
|
Developer.find_all nil, 'id ASC', [3, 8] # return three developers, starting from #8 and forward
|
3133
3146
|
|
3134
|
-
This doesn't yet work with the DB2 or MS SQL adapters. Patches to make that happen are encouraged.
|
3147
|
+
This doesn't yet work with the DB2 or MS SQL adapters. Patches to make that happen are encouraged.
|
3135
3148
|
|
3136
3149
|
* Added alias_method :to_param, :id to Base, such that Active Record objects to be used as URL parameters in Action Pack automatically #812 [Nicholas Seckar/Sam Stephenson]
|
3137
3150
|
|
@@ -3166,8 +3179,8 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3166
3179
|
|
3167
3180
|
* Added MultiparameterAssignmentErrors and AttributeAssignmentError exceptions #777 [demetrius]. Documentation:
|
3168
3181
|
|
3169
|
-
* +MultiparameterAssignmentErrors+ -- collection of errors that occurred during a mass assignment using the
|
3170
|
-
+attributes=+ method. The +errors+ property of this exception contains an array of +AttributeAssignmentError+
|
3182
|
+
* +MultiparameterAssignmentErrors+ -- collection of errors that occurred during a mass assignment using the
|
3183
|
+
+attributes=+ method. The +errors+ property of this exception contains an array of +AttributeAssignmentError+
|
3171
3184
|
objects that should be inspected to determine which attributes triggered the errors.
|
3172
3185
|
* +AttributeAssignmentError+ -- an error occurred while doing a mass assignment through the +attributes=+ method.
|
3173
3186
|
You can inspect the +attribute+ property of the exception object to determine which attribute triggered the error.
|
@@ -3253,11 +3266,11 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3253
3266
|
|
3254
3267
|
* Fixed the SQL Server adapter on a bunch of issues #667 [DeLynn]
|
3255
3268
|
|
3256
|
-
1. Created a new columns method that is much cleaner.
|
3257
|
-
2. Corrected a problem with the select and select_all methods
|
3258
|
-
that didn't account for the LIMIT clause being passed into raw SQL statements.
|
3259
|
-
3. Implemented the string_to_time method in order to create proper instances of the time class.
|
3260
|
-
4. Added logic to the simplified_type method that allows the database to specify the scale of float data.
|
3269
|
+
1. Created a new columns method that is much cleaner.
|
3270
|
+
2. Corrected a problem with the select and select_all methods
|
3271
|
+
that didn't account for the LIMIT clause being passed into raw SQL statements.
|
3272
|
+
3. Implemented the string_to_time method in order to create proper instances of the time class.
|
3273
|
+
4. Added logic to the simplified_type method that allows the database to specify the scale of float data.
|
3261
3274
|
5. Adjusted the quote_column_name to account for the fact that MS SQL is bothered by a forward slash in the data string.
|
3262
3275
|
|
3263
3276
|
* Fixed that the dynamic finder like find_all_by_something_boolean(false) didn't work #649 [lmarlow]
|
@@ -3380,9 +3393,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3380
3393
|
|
3381
3394
|
* Fixed binary support for PostgreSQL #444 [alex@byzantine.no]
|
3382
3395
|
|
3383
|
-
* Added a differenciation between AssociationCollection#size and -length. Now AssociationCollection#size returns the size of the
|
3384
|
-
collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and calling collection.size if it has. If
|
3385
|
-
it's more likely than not that the collection does have a size larger than zero and you need to fetch that collection afterwards,
|
3396
|
+
* Added a differenciation between AssociationCollection#size and -length. Now AssociationCollection#size returns the size of the
|
3397
|
+
collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and calling collection.size if it has. If
|
3398
|
+
it's more likely than not that the collection does have a size larger than zero and you need to fetch that collection afterwards,
|
3386
3399
|
it'll take one less SELECT query if you use length.
|
3387
3400
|
|
3388
3401
|
* Added Base#attributes that returns a hash of all the attributes with their names as keys and clones of their objects as values #433 [atyp.de]
|
@@ -3395,7 +3408,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3395
3408
|
|
3396
3409
|
* Added SQLite3 compatibility through the sqlite3-ruby adapter by Jamis Buck #381 [Jeremy Kemper]
|
3397
3410
|
|
3398
|
-
* Added support for the new protocol spoken by MySQL 4.1.1+ servers for the Ruby/MySQL adapter that ships with Rails #440 [Matt Mower]
|
3411
|
+
* Added support for the new protocol spoken by MySQL 4.1.1+ servers for the Ruby/MySQL adapter that ships with Rails #440 [Matt Mower]
|
3399
3412
|
|
3400
3413
|
* Added that Observers can use the observes class method instead of overwriting self.observed_class().
|
3401
3414
|
|
@@ -3458,7 +3471,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3458
3471
|
class Post < ActiveRecord::Base
|
3459
3472
|
has_one :tagging, :as => :taggable
|
3460
3473
|
end
|
3461
|
-
|
3474
|
+
|
3462
3475
|
Post.find :all, :include => :tagging
|
3463
3476
|
|
3464
3477
|
* Added descriptive error messages for invalid has_many :through associations: going through :has_one or :has_and_belongs_to_many [Rick Olson]
|
@@ -3469,7 +3482,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3469
3482
|
has_many :photos, :as => :photographic
|
3470
3483
|
belongs_to :firm
|
3471
3484
|
end
|
3472
|
-
|
3485
|
+
|
3473
3486
|
class Firm < ActiveRecord::Base
|
3474
3487
|
has_many :photo_collections
|
3475
3488
|
has_many :photos, :through => :photo_collections
|
@@ -3531,7 +3544,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3531
3544
|
|
3532
3545
|
In this example, :include => false disables the default eager association from loading. :select changes the standard
|
3533
3546
|
select clause. :joins specifies a join that is added to the end of the has_many :through query.
|
3534
|
-
|
3547
|
+
|
3535
3548
|
class Post < ActiveRecord::Base
|
3536
3549
|
has_many :tags, :through => :taggings, :include => :tagging do
|
3537
3550
|
def add_joins_and_select
|
@@ -3540,7 +3553,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3540
3553
|
end
|
3541
3554
|
end
|
3542
3555
|
end
|
3543
|
-
|
3556
|
+
|
3544
3557
|
* Fixed that schema changes while the database was open would break any connections to a SQLite database (now we reconnect if that error is throw) [David Heinemeier Hansson]
|
3545
3558
|
|
3546
3559
|
* Don't classify the has_one class when eager loading, it is already singular. Add tests. (closes #4117) [Jonathan Viney]
|
@@ -3557,12 +3570,12 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3557
3570
|
has_many :clients
|
3558
3571
|
has_many :invoices, :through => :clients
|
3559
3572
|
end
|
3560
|
-
|
3573
|
+
|
3561
3574
|
class Client < ActiveRecord::Base
|
3562
3575
|
belongs_to :firm
|
3563
3576
|
has_many :invoices
|
3564
3577
|
end
|
3565
|
-
|
3578
|
+
|
3566
3579
|
class Invoice < ActiveRecord::Base
|
3567
3580
|
belongs_to :client
|
3568
3581
|
end
|
@@ -3614,19 +3627,19 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3614
3627
|
class CachedModel < ActiveRecord::Base
|
3615
3628
|
self.abstract_class = true
|
3616
3629
|
end
|
3617
|
-
|
3630
|
+
|
3618
3631
|
class Post < CachedModel
|
3619
3632
|
end
|
3620
|
-
|
3633
|
+
|
3621
3634
|
CachedModel.abstract_class?
|
3622
3635
|
=> true
|
3623
|
-
|
3636
|
+
|
3624
3637
|
Post.abstract_class?
|
3625
3638
|
=> false
|
3626
3639
|
|
3627
3640
|
Post.base_class
|
3628
3641
|
=> Post
|
3629
|
-
|
3642
|
+
|
3630
3643
|
Post.table_name
|
3631
3644
|
=> 'posts'
|
3632
3645
|
|
@@ -3651,9 +3664,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3651
3664
|
* Added Base#to_xml that'll turn the current record into a XML representation [David Heinemeier Hansson]. Example:
|
3652
3665
|
|
3653
3666
|
topic.to_xml
|
3654
|
-
|
3667
|
+
|
3655
3668
|
...returns:
|
3656
|
-
|
3669
|
+
|
3657
3670
|
<?xml version="1.0" encoding="UTF-8"?>
|
3658
3671
|
<topic>
|
3659
3672
|
<title>The First Topic</title>
|
@@ -3668,13 +3681,13 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3668
3681
|
<parent-id></parent-id>
|
3669
3682
|
<last-read type="date">2004-04-15</last-read>
|
3670
3683
|
</topic>
|
3671
|
-
|
3684
|
+
|
3672
3685
|
...and you can configure with:
|
3673
|
-
|
3686
|
+
|
3674
3687
|
topic.to_xml(:skip_instruct => true, :except => [ :id, bonus_time, :written_on, replies_count ])
|
3675
|
-
|
3688
|
+
|
3676
3689
|
...that'll return:
|
3677
|
-
|
3690
|
+
|
3678
3691
|
<topic>
|
3679
3692
|
<title>The First Topic</title>
|
3680
3693
|
<author-name>David</author-name>
|
@@ -3684,13 +3697,13 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3684
3697
|
<parent-id></parent-id>
|
3685
3698
|
<last-read type="date">2004-04-15</last-read>
|
3686
3699
|
</topic>
|
3687
|
-
|
3700
|
+
|
3688
3701
|
You can even do load first-level associations as part of the document:
|
3689
|
-
|
3702
|
+
|
3690
3703
|
firm.to_xml :include => [ :account, :clients ]
|
3691
|
-
|
3704
|
+
|
3692
3705
|
...that'll return something like:
|
3693
|
-
|
3706
|
+
|
3694
3707
|
<?xml version="1.0" encoding="UTF-8"?>
|
3695
3708
|
<firm>
|
3696
3709
|
<id type="integer">1</id>
|
@@ -3710,7 +3723,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3710
3723
|
<id type="integer">1</id>
|
3711
3724
|
<credit-limit type="integer">50</credit-limit>
|
3712
3725
|
</account>
|
3713
|
-
</firm>
|
3726
|
+
</firm>
|
3714
3727
|
|
3715
3728
|
* Allow :counter_cache to take a column name for custom counter cache columns [Jamis Buck]
|
3716
3729
|
|
@@ -3728,9 +3741,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3728
3741
|
|
3729
3742
|
* The first time a table is referenced in a join, no alias is used.
|
3730
3743
|
* After that, the parent class name and the reflection name are used.
|
3731
|
-
|
3744
|
+
|
3732
3745
|
Tree.find(:all, :include => :children) # LEFT OUTER JOIN trees AS tree_children ...
|
3733
|
-
|
3746
|
+
|
3734
3747
|
* Any additional join references get a numerical suffix like '_2', '_3', etc.
|
3735
3748
|
|
3736
3749
|
* Fixed eager loading problems with single-table inheritance #3580 [Rick Olson]. Post.find(:all, :include => :special_comments) now returns all posts, and any special comments that the posts may have. And made STI work with has_many :through and polymorphic belongs_to.
|
@@ -3742,28 +3755,28 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3742
3755
|
=> authors
|
3743
3756
|
+- posts
|
3744
3757
|
+- comments
|
3745
|
-
|
3758
|
+
|
3746
3759
|
# cascaded in two levels and normal association
|
3747
3760
|
>> Author.find(:all, :include=>[{:posts=>:comments}, :categorizations])
|
3748
3761
|
=> authors
|
3749
3762
|
+- posts
|
3750
3763
|
+- comments
|
3751
3764
|
+- categorizations
|
3752
|
-
|
3765
|
+
|
3753
3766
|
# cascaded in two levels with two has_many associations
|
3754
3767
|
>> Author.find(:all, :include=>{:posts=>[:comments, :categorizations]})
|
3755
3768
|
=> authors
|
3756
3769
|
+- posts
|
3757
3770
|
+- comments
|
3758
3771
|
+- categorizations
|
3759
|
-
|
3772
|
+
|
3760
3773
|
# cascaded in three levels
|
3761
3774
|
>> Company.find(:all, :include=>{:groups=>{:members=>{:favorites}}})
|
3762
3775
|
=> companies
|
3763
3776
|
+- groups
|
3764
3777
|
+- members
|
3765
3778
|
+- favorites
|
3766
|
-
|
3779
|
+
|
3767
3780
|
* Make counter cache work when replacing an association #3245 [eugenol@gmail.com]
|
3768
3781
|
|
3769
3782
|
* Make migrations verbose [Jamis Buck]
|
@@ -3900,17 +3913,17 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3900
3913
|
|
3901
3914
|
* Fixed that saving a model with multiple habtm associations would only save the first one. #3244 [yanowitz-rubyonrails@quantumfoam.org, Florian Weber]
|
3902
3915
|
|
3903
|
-
* Fix change_column to work with PostgreSQL 7.x and 8.x. #3141 [wejn@box.cz, Rick Olson, Scott Barron]
|
3916
|
+
* Fix change_column to work with PostgreSQL 7.x and 8.x. #3141 [wejn@box.cz, Rick Olson, Scott Barron]
|
3904
3917
|
|
3905
|
-
* removed :piggyback in favor of just allowing :select on :through associations. [Tobias Lütke]
|
3918
|
+
* removed :piggyback in favor of just allowing :select on :through associations. [Tobias Lütke]
|
3906
3919
|
|
3907
|
-
* made method missing delegation to class methods on relation target work on :through associations. [Tobias Lütke]
|
3920
|
+
* made method missing delegation to class methods on relation target work on :through associations. [Tobias Lütke]
|
3908
3921
|
|
3909
|
-
* made .find() work on :through relations. [Tobias Lütke]
|
3922
|
+
* made .find() work on :through relations. [Tobias Lütke]
|
3910
3923
|
|
3911
3924
|
* Fix typo in association docs. #3296. [Blair Zajac]
|
3912
3925
|
|
3913
|
-
* Fixed :through relations when using STI inherited classes would use the inherited class's name as foreign key on the join model [Tobias Lütke]
|
3926
|
+
* Fixed :through relations when using STI inherited classes would use the inherited class's name as foreign key on the join model [Tobias Lütke]
|
3914
3927
|
|
3915
3928
|
*1.13.2* (December 13th, 2005)
|
3916
3929
|
|
@@ -3923,7 +3936,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
3923
3936
|
class Post
|
3924
3937
|
has_many :recent_comments, :class_name => "Comment", :limit => 10, :include => :author
|
3925
3938
|
end
|
3926
|
-
|
3939
|
+
|
3927
3940
|
post.recent_comments.find(:all) # Uses LIMIT 10 and includes authors
|
3928
3941
|
post.recent_comments.find(:all, :limit => nil) # Uses no limit but include authors
|
3929
3942
|
post.recent_comments.find(:all, :limit => nil, :include => nil) # Uses no limit and doesn't include authors
|
@@ -4072,9 +4085,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4072
4085
|
# Associated with :post_id
|
4073
4086
|
Comment.create :body => "Hello world"
|
4074
4087
|
end
|
4075
|
-
|
4088
|
+
|
4076
4089
|
This is rarely used directly, but allows for find_or_create on associations. So you can do:
|
4077
|
-
|
4090
|
+
|
4078
4091
|
# If the tag doesn't exist, a new one is created that's associated with the person
|
4079
4092
|
person.tags.find_or_create_by_name("Summer")
|
4080
4093
|
|
@@ -4082,7 +4095,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4082
4095
|
|
4083
4096
|
# No 'Summer' tag exists
|
4084
4097
|
Tag.find_or_create_by_name("Summer") # equal to Tag.create(:name => "Summer")
|
4085
|
-
|
4098
|
+
|
4086
4099
|
# Now the 'Summer' tag does exist
|
4087
4100
|
Tag.find_or_create_by_name("Summer") # equal to Tag.find_by_name("Summer")
|
4088
4101
|
|
@@ -4173,7 +4186,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4173
4186
|
|
4174
4187
|
* YAML fixtures support ordered hashes for fixtures with foreign key dependencies in the same table. #1896 [purestorm@ggnore.net]
|
4175
4188
|
|
4176
|
-
* :dependent now accepts :nullify option. Sets the foreign key of the related objects to NULL instead of deleting them. #2015 [Robby Russell <robby@planetargon.com>]
|
4189
|
+
* :dependent now accepts :nullify option. Sets the foreign key of the related objects to NULL instead of deleting them. #2015 [Robby Russell <robby@planetargon.com>]
|
4177
4190
|
|
4178
4191
|
* Introduce read-only records. If you call object.readonly! then it will mark the object as read-only and raise ReadOnlyRecord if you call object.save. object.readonly? reports whether the object is read-only. Passing :readonly => true to any finder method will mark returned records as read-only. The :joins option now implies :readonly, so if you use this option, saving the same record will now fail. Use find_by_sql to work around.
|
4179
4192
|
|
@@ -4328,14 +4341,14 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4328
4341
|
def self.search(q)
|
4329
4342
|
find(:all, :conditions => ["body = ?", q])
|
4330
4343
|
end
|
4331
|
-
end
|
4344
|
+
end
|
4332
4345
|
|
4333
4346
|
class Post < AR:B
|
4334
4347
|
has_many :comments
|
4335
4348
|
end
|
4336
4349
|
|
4337
4350
|
Post.find(1).comments.search('hi') # => SELECT * from comments WHERE post_id = 1 AND body = 'hi'
|
4338
|
-
|
4351
|
+
|
4339
4352
|
NOTICE: This patch changes the underlying SQL generated by has_and_belongs_to_many queries. If your relying on that, such as
|
4340
4353
|
by explicitly referencing the old t and j aliases, you'll need to update your code. Of course, you _shouldn't_ be relying on
|
4341
4354
|
details like that no less than you should be diving in to touch private variables. But just in case you do, consider yourself
|
@@ -4383,14 +4396,14 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4383
4396
|
|
4384
4397
|
class Project
|
4385
4398
|
has_and_belongs_to_many :developers, :before_add => :evaluate_velocity
|
4386
|
-
|
4399
|
+
|
4387
4400
|
def evaluate_velocity(developer)
|
4388
4401
|
...
|
4389
4402
|
end
|
4390
|
-
end
|
4391
|
-
|
4403
|
+
end
|
4404
|
+
|
4392
4405
|
..raising an exception will cause the object not to be added (or removed, with before_remove).
|
4393
|
-
|
4406
|
+
|
4394
4407
|
|
4395
4408
|
* Fixed Base.content_columns call for SQL Server adapter #1450 [DeLynn Berry]
|
4396
4409
|
|
@@ -4419,14 +4432,14 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4419
4432
|
* Fixed Base#find to honor the documentation on how :joins work and make them consistent with Base#count #1405 [pritchie@gmail.com]. What used to be:
|
4420
4433
|
|
4421
4434
|
Developer.find :all, :joins => 'developers_projects', :conditions => 'id=developer_id AND project_id=1'
|
4422
|
-
|
4435
|
+
|
4423
4436
|
...should instead be:
|
4424
|
-
|
4437
|
+
|
4425
4438
|
Developer.find(
|
4426
|
-
:all,
|
4427
|
-
:joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
4439
|
+
:all,
|
4440
|
+
:joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
|
4428
4441
|
:conditions => 'project_id=1'
|
4429
|
-
)
|
4442
|
+
)
|
4430
4443
|
|
4431
4444
|
* Fixed that validations didn't respecting custom setting for too_short, too_long messages #1437 [Marcel Molina Jr.]
|
4432
4445
|
|
@@ -4445,12 +4458,12 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4445
4458
|
|
4446
4459
|
david.projects = [Project.find(1), Project.new("name" => "ActionWebSearch")]
|
4447
4460
|
david.save
|
4448
|
-
|
4461
|
+
|
4449
4462
|
If david.projects already contain the project with ID 1, this is left unchanged. Any other projects are dropped. And the new
|
4450
4463
|
project is saved when david.save is called.
|
4451
|
-
|
4464
|
+
|
4452
4465
|
Also included is a way to do assignments through IDs, which is perfect for checkbox updating, so you get to do:
|
4453
|
-
|
4466
|
+
|
4454
4467
|
david.project_ids = [1, 5, 7]
|
4455
4468
|
|
4456
4469
|
* Corrected typo in find SQL for has_and_belongs_to_many. #1312 [ben@bensinclair.com]
|
@@ -4463,7 +4476,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4463
4476
|
|
4464
4477
|
* Return PostgreSQL columns in the order they were declared #1374 [perlguy@gmail.com]
|
4465
4478
|
|
4466
|
-
* Allow before/after update hooks to work on models using optimistic locking
|
4479
|
+
* Allow before/after update hooks to work on models using optimistic locking
|
4467
4480
|
|
4468
4481
|
* Eager loading of dependent has_one associations won't delete the association #1212
|
4469
4482
|
|
@@ -4494,7 +4507,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4494
4507
|
|
4495
4508
|
Conditional validations can also solve the salted login generator problem:
|
4496
4509
|
validates_confirmation_of :password, :if => :new_password?
|
4497
|
-
|
4510
|
+
|
4498
4511
|
Using blocks:
|
4499
4512
|
validates_presence_of :username, :if => Proc.new { |user| user.signup_step > 1 }
|
4500
4513
|
|
@@ -4557,11 +4570,11 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4557
4570
|
puts "Written by: " + post.author.name
|
4558
4571
|
puts "Last comment on: " + post.comments.first.created_on
|
4559
4572
|
end
|
4560
|
-
|
4573
|
+
|
4561
4574
|
This used to generate 301 database queries if all 100 posts had both author and comments. It can now be written as:
|
4562
|
-
|
4575
|
+
|
4563
4576
|
for post in Post.find(:all, :limit => 100, :include => [ :author, :comments ])
|
4564
|
-
|
4577
|
+
|
4565
4578
|
...and the number of database queries needed is now 1.
|
4566
4579
|
|
4567
4580
|
* Added new unified Base.find API and deprecated the use of find_first and find_all. See the documentation for Base.find. Examples:
|
@@ -4643,10 +4656,10 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4643
4656
|
|
4644
4657
|
* Added adapter independent limit clause as a two-element array with the first being the limit, the second being the offset #795 [Sam Stephenson]. Example:
|
4645
4658
|
|
4646
|
-
Developer.find_all nil, 'id ASC', 5 # return the first five developers
|
4659
|
+
Developer.find_all nil, 'id ASC', 5 # return the first five developers
|
4647
4660
|
Developer.find_all nil, 'id ASC', [3, 8] # return three developers, starting from #8 and forward
|
4648
|
-
|
4649
|
-
This doesn't yet work with the DB2 or MS SQL adapters. Patches to make that happen are encouraged.
|
4661
|
+
|
4662
|
+
This doesn't yet work with the DB2 or MS SQL adapters. Patches to make that happen are encouraged.
|
4650
4663
|
|
4651
4664
|
* Added alias_method :to_param, :id to Base, such that Active Record objects to be used as URL parameters in Action Pack automatically #812 [Nicholas Seckar/Sam Stephenson]
|
4652
4665
|
|
@@ -4681,8 +4694,8 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4681
4694
|
|
4682
4695
|
* Added MultiparameterAssignmentErrors and AttributeAssignmentError exceptions #777 [demetrius]. Documentation:
|
4683
4696
|
|
4684
|
-
* +MultiparameterAssignmentErrors+ -- collection of errors that occurred during a mass assignment using the
|
4685
|
-
+attributes=+ method. The +errors+ property of this exception contains an array of +AttributeAssignmentError+
|
4697
|
+
* +MultiparameterAssignmentErrors+ -- collection of errors that occurred during a mass assignment using the
|
4698
|
+
+attributes=+ method. The +errors+ property of this exception contains an array of +AttributeAssignmentError+
|
4686
4699
|
objects that should be inspected to determine which attributes triggered the errors.
|
4687
4700
|
* +AttributeAssignmentError+ -- an error occurred while doing a mass assignment through the +attributes=+ method.
|
4688
4701
|
You can inspect the +attribute+ property of the exception object to determine which attribute triggered the error.
|
@@ -4710,16 +4723,16 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4710
4723
|
Validates whether the value of the specified attribute is numeric by trying to convert it to
|
4711
4724
|
a float with Kernel.Float (if <tt>integer</tt> is false) or applying it to the regular expression
|
4712
4725
|
<tt>/^[\+\-]?\d+$/</tt> (if <tt>integer</tt> is set to true).
|
4713
|
-
|
4726
|
+
|
4714
4727
|
class Person < ActiveRecord::Base
|
4715
4728
|
validates_numericality_of :value, :on => :create
|
4716
4729
|
end
|
4717
|
-
|
4730
|
+
|
4718
4731
|
Configuration options:
|
4719
4732
|
* <tt>message</tt> - A custom error message (default is: "is not a number")
|
4720
4733
|
* <tt>on</tt> Specifies when this validation is active (default is :save, other options :create, :update)
|
4721
4734
|
* <tt>only_integer</tt> Specifies whether the value has to be an integer, e.g. an integral value (default is false)
|
4722
|
-
|
4735
|
+
|
4723
4736
|
|
4724
4737
|
* Fixed that HasManyAssociation#count was using :finder_sql rather than :counter_sql if it was available #445 [Scott Barron]
|
4725
4738
|
|
@@ -4768,17 +4781,17 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4768
4781
|
|
4769
4782
|
* Fixed the SQL Server adapter on a bunch of issues #667 [DeLynn]
|
4770
4783
|
|
4771
|
-
1. Created a new columns method that is much cleaner.
|
4772
|
-
2. Corrected a problem with the select and select_all methods
|
4773
|
-
that didn't account for the LIMIT clause being passed into raw SQL statements.
|
4774
|
-
3. Implemented the string_to_time method in order to create proper instances of the time class.
|
4775
|
-
4. Added logic to the simplified_type method that allows the database to specify the scale of float data.
|
4784
|
+
1. Created a new columns method that is much cleaner.
|
4785
|
+
2. Corrected a problem with the select and select_all methods
|
4786
|
+
that didn't account for the LIMIT clause being passed into raw SQL statements.
|
4787
|
+
3. Implemented the string_to_time method in order to create proper instances of the time class.
|
4788
|
+
4. Added logic to the simplified_type method that allows the database to specify the scale of float data.
|
4776
4789
|
5. Adjusted the quote_column_name to account for the fact that MS SQL is bothered by a forward slash in the data string.
|
4777
4790
|
|
4778
4791
|
* Fixed that the dynamic finder like find_all_by_something_boolean(false) didn't work #649 [lmarlow]
|
4779
4792
|
|
4780
4793
|
* Added validates_each that validates each specified attribute against a block #610 [Jeremy Kemper]. Example:
|
4781
|
-
|
4794
|
+
|
4782
4795
|
class Person < ActiveRecord::Base
|
4783
4796
|
validates_each :first_name, :last_name do |record, attr|
|
4784
4797
|
record.errors.add attr, 'starts with z.' if attr[0] == ?z
|
@@ -4856,19 +4869,19 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4856
4869
|
class Book < ActiveRecord::Base
|
4857
4870
|
has_many :pages
|
4858
4871
|
belongs_to :library
|
4859
|
-
|
4872
|
+
|
4860
4873
|
validates_associated :pages, :library
|
4861
4874
|
end
|
4862
|
-
|
4875
|
+
|
4863
4876
|
* Added support for associating unsaved objects #402 [Tim Bates]. Rules that govern this addition:
|
4864
4877
|
|
4865
4878
|
== Unsaved objects and associations
|
4866
|
-
|
4879
|
+
|
4867
4880
|
You can manipulate objects and associations before they are saved to the database, but there is some special behaviour you should be
|
4868
4881
|
aware of, mostly involving the saving of associated objects.
|
4869
|
-
|
4882
|
+
|
4870
4883
|
=== One-to-one associations
|
4871
|
-
|
4884
|
+
|
4872
4885
|
* Assigning an object to a has_one association automatically saves that object, and the object being replaced (if there is one), in
|
4873
4886
|
order to update their primary keys - except if the parent object is unsaved (new_record? == true).
|
4874
4887
|
* If either of these saves fail (due to one of the objects being invalid) the assignment statement returns false and the assignment
|
@@ -4876,9 +4889,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4876
4889
|
* If you wish to assign an object to a has_one association without saving it, use the #association.build method (documented below).
|
4877
4890
|
* Assigning an object to a belongs_to association does not save the object, since the foreign key field belongs on the parent. It does
|
4878
4891
|
not save the parent either.
|
4879
|
-
|
4892
|
+
|
4880
4893
|
=== Collections
|
4881
|
-
|
4894
|
+
|
4882
4895
|
* Adding an object to a collection (has_many or has_and_belongs_to_many) automatically saves that object, except if the parent object
|
4883
4896
|
(the owner of the collection) is not yet stored in the database.
|
4884
4897
|
* If saving any of the objects being added to a collection (via #push or similar) fails, then #push returns false.
|
@@ -4895,9 +4908,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4895
4908
|
|
4896
4909
|
* Fixed binary support for PostgreSQL #444 [alex@byzantine.no]
|
4897
4910
|
|
4898
|
-
* Added a differenciation between AssociationCollection#size and -length. Now AssociationCollection#size returns the size of the
|
4899
|
-
collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and calling collection.size if it has. If
|
4900
|
-
it's more likely than not that the collection does have a size larger than zero and you need to fetch that collection afterwards,
|
4911
|
+
* Added a differenciation between AssociationCollection#size and -length. Now AssociationCollection#size returns the size of the
|
4912
|
+
collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and calling collection.size if it has. If
|
4913
|
+
it's more likely than not that the collection does have a size larger than zero and you need to fetch that collection afterwards,
|
4901
4914
|
it'll take one less SELECT query if you use length.
|
4902
4915
|
|
4903
4916
|
* Added Base#attributes that returns a hash of all the attributes with their names as keys and clones of their objects as values #433 [atyp.de]
|
@@ -4910,7 +4923,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4910
4923
|
|
4911
4924
|
* Added SQLite3 compatibility through the sqlite3-ruby adapter by Jamis Buck #381 [Jeremy Kemper]
|
4912
4925
|
|
4913
|
-
* Added support for the new protocol spoken by MySQL 4.1.1+ servers for the Ruby/MySQL adapter that ships with Rails #440 [Matt Mower]
|
4926
|
+
* Added support for the new protocol spoken by MySQL 4.1.1+ servers for the Ruby/MySQL adapter that ships with Rails #440 [Matt Mower]
|
4914
4927
|
|
4915
4928
|
* Added that Observers can use the observes class method instead of overwriting self.observed_class().
|
4916
4929
|
|
@@ -4918,7 +4931,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4918
4931
|
class ListSweeper < ActiveRecord::Base
|
4919
4932
|
def self.observed_class() [ List, Item ]
|
4920
4933
|
end
|
4921
|
-
|
4934
|
+
|
4922
4935
|
After:
|
4923
4936
|
class ListSweeper < ActiveRecord::Base
|
4924
4937
|
observes List, Item
|
@@ -4938,7 +4951,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4938
4951
|
page.views # => 1
|
4939
4952
|
page.increment!(:views) # executes an UPDATE statement
|
4940
4953
|
page.views # => 2
|
4941
|
-
|
4954
|
+
|
4942
4955
|
page.increment(:views).increment!(:views)
|
4943
4956
|
page.views # => 4
|
4944
4957
|
|
@@ -4950,32 +4963,32 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4950
4963
|
* Added automated optimistic locking if the field <tt>lock_version</tt> is present. Each update to the
|
4951
4964
|
record increments the lock_version column and the locking facilities ensure that records instantiated twice
|
4952
4965
|
will let the last one saved raise a StaleObjectError if the first was also updated. Example:
|
4953
|
-
|
4966
|
+
|
4954
4967
|
p1 = Person.find(1)
|
4955
4968
|
p2 = Person.find(1)
|
4956
|
-
|
4969
|
+
|
4957
4970
|
p1.first_name = "Michael"
|
4958
4971
|
p1.save
|
4959
|
-
|
4972
|
+
|
4960
4973
|
p2.first_name = "should fail"
|
4961
4974
|
p2.save # Raises a ActiveRecord::StaleObjectError
|
4962
|
-
|
4975
|
+
|
4963
4976
|
You're then responsible for dealing with the conflict by rescuing the exception and either rolling back, merging,
|
4964
4977
|
or otherwise apply the business logic needed to resolve the conflict.
|
4965
4978
|
|
4966
4979
|
#384 [Michael Koziarski]
|
4967
4980
|
|
4968
|
-
* Added dynamic attribute-based finders as a cleaner way of getting objects by simple queries without turning to SQL.
|
4981
|
+
* Added dynamic attribute-based finders as a cleaner way of getting objects by simple queries without turning to SQL.
|
4969
4982
|
They work by appending the name of an attribute to <tt>find_by_</tt>, so you get finders like <tt>Person.find_by_user_name,
|
4970
4983
|
Payment.find_by_transaction_id</tt>. So instead of writing <tt>Person.find_first(["user_name = ?", user_name])</tt>, you just do
|
4971
4984
|
<tt>Person.find_by_user_name(user_name)</tt>.
|
4972
|
-
|
4985
|
+
|
4973
4986
|
It's also possible to use multiple attributes in the same find by separating them with "_and_", so you get finders like
|
4974
4987
|
<tt>Person.find_by_user_name_and_password</tt> or even <tt>Payment.find_by_purchaser_and_state_and_country</tt>. So instead of writing
|
4975
|
-
<tt>Person.find_first(["user_name = ? AND password = ?", user_name, password])</tt>, you just do
|
4988
|
+
<tt>Person.find_first(["user_name = ? AND password = ?", user_name, password])</tt>, you just do
|
4976
4989
|
<tt>Person.find_by_user_name_and_password(user_name, password)</tt>.
|
4977
4990
|
|
4978
|
-
While primarily a construct for easier find_firsts, it can also be used as a construct for find_all by using calls like
|
4991
|
+
While primarily a construct for easier find_firsts, it can also be used as a construct for find_all by using calls like
|
4979
4992
|
<tt>Payment.find_all_by_amount(50)</tt> that is turned into <tt>Payment.find_all(["amount = ?", 50])</tt>. This is something not as equally useful,
|
4980
4993
|
though, as it's not possible to specify the order in which the objects are returned.
|
4981
4994
|
|
@@ -4983,13 +4996,13 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
4983
4996
|
|
4984
4997
|
Before:
|
4985
4998
|
before_destroy(Proc.new{ |record| Person.destroy_all "firm_id = #{record.id}" })
|
4986
|
-
|
4999
|
+
|
4987
5000
|
After:
|
4988
5001
|
before_destroy { |record| Person.destroy_all "firm_id = #{record.id}" }
|
4989
5002
|
|
4990
5003
|
* Added :counter_cache option to acts_as_tree that works just like the one you can define on belongs_to #371 [Josh Peek]
|
4991
5004
|
|
4992
|
-
* Added Base.default_timezone accessor that determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates
|
5005
|
+
* Added Base.default_timezone accessor that determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates
|
4993
5006
|
and times from the database. This is set to :local by default.
|
4994
5007
|
|
4995
5008
|
* Added the possibility for adapters to overwrite add_limit! to implement a different limiting scheme than "LIMIT X" used by MySQL, PostgreSQL, and SQLite.
|
@@ -5008,7 +5021,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5008
5021
|
|
5009
5022
|
* Fixed a bug in the Ruby/MySQL that caused binary content to be escaped badly and come back mangled #405 [Tobias Lütke]
|
5010
5023
|
|
5011
|
-
* Fixed that the const_missing autoload assumes the requested constant is set by require_association and calls const_get to retrieve it.
|
5024
|
+
* Fixed that the const_missing autoload assumes the requested constant is set by require_association and calls const_get to retrieve it.
|
5012
5025
|
If require_association did not set the constant then const_get will call const_missing, resulting in an infinite loop #380 [Jeremy Kemper]
|
5013
5026
|
|
5014
5027
|
* Fixed broken transactions that were actually only running object-level and not db level transactions [andreas]
|
@@ -5028,12 +5041,12 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5028
5041
|
require_association 'person'
|
5029
5042
|
class Employee < Person
|
5030
5043
|
end
|
5031
|
-
|
5044
|
+
|
5032
5045
|
after:
|
5033
5046
|
class Employee < Person
|
5034
5047
|
end
|
5035
5048
|
|
5036
|
-
This also reduces the usefulness of Controller.model in Action Pack to currently only being for documentation purposes.
|
5049
|
+
This also reduces the usefulness of Controller.model in Action Pack to currently only being for documentation purposes.
|
5037
5050
|
|
5038
5051
|
* Added that Base.update_all and Base.delete_all return an integer of the number of affected rows #341
|
5039
5052
|
|
@@ -5051,12 +5064,12 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5051
5064
|
|
5052
5065
|
* Added more informative exceptions in establish_connection #356 [Jeremy Kemper]
|
5053
5066
|
|
5054
|
-
* Added Base#update_attributes that'll accept a hash of attributes and save the record (returning true if it passed validation, false otherwise).
|
5067
|
+
* Added Base#update_attributes that'll accept a hash of attributes and save the record (returning true if it passed validation, false otherwise).
|
5055
5068
|
|
5056
5069
|
Before:
|
5057
5070
|
person.attributes = @params["person"]
|
5058
5071
|
person.save
|
5059
|
-
|
5072
|
+
|
5060
5073
|
Now:
|
5061
5074
|
person.update_attributes(@params["person"])
|
5062
5075
|
|
@@ -5068,7 +5081,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5068
5081
|
|
5069
5082
|
* Fixed that options[:counter_sql] was overwritten with interpolated sql rather than original sql #355 [Jeremy Kemper]
|
5070
5083
|
|
5071
|
-
* Fixed that overriding an attribute's accessor would be disregarded by add_on_empty and add_on_boundary_breaking because they simply used
|
5084
|
+
* Fixed that overriding an attribute's accessor would be disregarded by add_on_empty and add_on_boundary_breaking because they simply used
|
5072
5085
|
the attributes[] hash instead of checking for @base.respond_to?(attr.to_s). [Marten]
|
5073
5086
|
|
5074
5087
|
* Fixed that Base.table_name would expect a parameter when used in has_and_belongs_to_many joins [Anna Lissa Cruz]
|
@@ -5102,10 +5115,10 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5102
5115
|
belongs_to :todo_list
|
5103
5116
|
end
|
5104
5117
|
|
5105
|
-
* Added acts_as_tree that can decorates an existing class with a many to many relationship with itself. Perfect for categories in
|
5118
|
+
* Added acts_as_tree that can decorates an existing class with a many to many relationship with itself. Perfect for categories in
|
5106
5119
|
categories and the likes. [Tobias Lütke]
|
5107
5120
|
|
5108
|
-
* Added that Active Records will automatically record creation and/or update timestamps of database objects if fields of the names
|
5121
|
+
* Added that Active Records will automatically record creation and/or update timestamps of database objects if fields of the names
|
5109
5122
|
created_at/created_on or updated_at/updated_on are present. [Tobias Lütke]
|
5110
5123
|
|
5111
5124
|
* Added Base.default_error_messages as a hash of all the error messages used in the validates_*_of so they can be changed in one place [Tobias Lütke]
|
@@ -5119,14 +5132,14 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5119
5132
|
* Added a better exception for when a type column is used in a table without the intention of triggering single-table inheritance. Example:
|
5120
5133
|
|
5121
5134
|
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'bad_class!'.
|
5122
|
-
This error is raised because the column 'type' is reserved for storing the class in case of inheritance.
|
5123
|
-
Please rename this column if you didn't intend it to be used for storing the inheritance class or
|
5135
|
+
This error is raised because the column 'type' is reserved for storing the class in case of inheritance.
|
5136
|
+
Please rename this column if you didn't intend it to be used for storing the inheritance class or
|
5124
5137
|
overwrite Company.inheritance_column to use another column for that information.
|
5125
5138
|
|
5126
5139
|
* Added that single-table inheritance will only kick in if the inheritance_column (by default "type") is present. Otherwise, inheritance won't
|
5127
5140
|
have any magic side effects.
|
5128
5141
|
|
5129
|
-
* Added the possibility of marking fields as being in error without adding a message (using nil) to it that'll get displayed wth full_messages #208 [mjobin]
|
5142
|
+
* Added the possibility of marking fields as being in error without adding a message (using nil) to it that'll get displayed wth full_messages #208 [mjobin]
|
5130
5143
|
|
5131
5144
|
* Fixed Base.errors to be indifferent as to whether strings or symbols are used. Examples:
|
5132
5145
|
|
@@ -5140,7 +5153,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5140
5153
|
errors.on(:name) # => "must be shorter"
|
5141
5154
|
errors.on("name") # => "must be shorter"
|
5142
5155
|
|
5143
|
-
* Added Base.validates_format_of that Validates whether the value of the specified attribute is of the correct form by matching
|
5156
|
+
* Added Base.validates_format_of that Validates whether the value of the specified attribute is of the correct form by matching
|
5144
5157
|
it against the regular expression provided. [Marcel Molina Jr.]
|
5145
5158
|
|
5146
5159
|
class Person < ActiveRecord::Base
|
@@ -5150,14 +5163,14 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5150
5163
|
* Added Base.validates_length_of that delegates to add_on_boundary_breaking #312 [Tobias Lütke]. Example:
|
5151
5164
|
|
5152
5165
|
Validates that the specified attribute matches the length restrictions supplied in either:
|
5153
|
-
|
5166
|
+
|
5154
5167
|
- configuration[:minimum]
|
5155
5168
|
- configuration[:maximum]
|
5156
5169
|
- configuration[:is]
|
5157
5170
|
- configuration[:within] (aka. configuration[:in])
|
5158
|
-
|
5171
|
+
|
5159
5172
|
Only one option can be used at a time.
|
5160
|
-
|
5173
|
+
|
5161
5174
|
class Person < ActiveRecord::Base
|
5162
5175
|
validates_length_of :first_name, :maximum=>30
|
5163
5176
|
validates_length_of :last_name, :maximum=>30, :message=>"less than %d if you don't mind"
|
@@ -5165,53 +5178,53 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5165
5178
|
validates_length_of :fav_bra_size, :minimum=>1, :too_short=>"please enter at least %d character"
|
5166
5179
|
validates_length_of :smurf_leader, :is=>4, :message=>"papa is spelled with %d characters... don't play me."
|
5167
5180
|
end
|
5168
|
-
|
5181
|
+
|
5169
5182
|
* Added Base.validate_presence as an alternative to implementing validate and doing errors.add_on_empty yourself.
|
5170
5183
|
|
5171
|
-
* Added Base.validates_uniqueness_of that alidates whether the value of the specified attributes are unique across the system.
|
5184
|
+
* Added Base.validates_uniqueness_of that alidates whether the value of the specified attributes are unique across the system.
|
5172
5185
|
Useful for making sure that only one user can be named "davidhh".
|
5173
|
-
|
5186
|
+
|
5174
5187
|
class Person < ActiveRecord::Base
|
5175
5188
|
validates_uniqueness_of :user_name
|
5176
5189
|
end
|
5177
|
-
|
5190
|
+
|
5178
5191
|
When the record is created, a check is performed to make sure that no record exist in the database with the given value for the specified
|
5179
5192
|
attribute (that maps to a column). When the record is updated, the same check is made but disregarding the record itself.
|
5180
5193
|
|
5181
5194
|
|
5182
5195
|
* Added Base.validates_confirmation_of that encapsulates the pattern of wanting to validate a password or email address field with a confirmation. Example:
|
5183
|
-
|
5196
|
+
|
5184
5197
|
Model:
|
5185
5198
|
class Person < ActiveRecord::Base
|
5186
5199
|
validates_confirmation_of :password
|
5187
5200
|
end
|
5188
|
-
|
5201
|
+
|
5189
5202
|
View:
|
5190
5203
|
<%= password_field "person", "password" %>
|
5191
5204
|
<%= password_field "person", "password_confirmation" %>
|
5192
|
-
|
5205
|
+
|
5193
5206
|
The person has to already have a password attribute (a column in the people table), but the password_confirmation is virtual.
|
5194
5207
|
It exists only as an in-memory variable for validating the password. This check is performed both on create and update.
|
5195
5208
|
|
5196
5209
|
|
5197
5210
|
* Added Base.validates_acceptance_of that encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement). Example:
|
5198
|
-
|
5211
|
+
|
5199
5212
|
class Person < ActiveRecord::Base
|
5200
5213
|
validates_acceptance_of :terms_of_service
|
5201
5214
|
end
|
5202
|
-
|
5215
|
+
|
5203
5216
|
The terms_of_service attribute is entirely virtual. No database column is needed. This check is performed both on create and update.
|
5204
5217
|
|
5205
5218
|
NOTE: The agreement is considered valid if it's set to the string "1". This makes it easy to relate it to an HTML checkbox.
|
5206
5219
|
|
5207
|
-
|
5220
|
+
|
5208
5221
|
* Added validation macros to make the stackable just like the lifecycle callbacks. Examples:
|
5209
5222
|
|
5210
5223
|
class Person < ActiveRecord::Base
|
5211
5224
|
validate { |record| record.errors.add("name", "too short") unless name.size > 10 }
|
5212
5225
|
validate { |record| record.errors.add("name", "too long") unless name.size < 20 }
|
5213
5226
|
validate_on_create :validate_password
|
5214
|
-
|
5227
|
+
|
5215
5228
|
private
|
5216
5229
|
def validate_password
|
5217
5230
|
errors.add("password", "too short") unless password.size > 6
|
@@ -5227,7 +5240,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5227
5240
|
through the database's own quoting routine. This should hopefully make it lots easier for new adapters that doesn't accept '1' for integer
|
5228
5241
|
columns.
|
5229
5242
|
|
5230
|
-
* Fixed has_and_belongs_to_many guessing of foreign key so that keys are generated correctly for models like SomeVerySpecialClient
|
5243
|
+
* Fixed has_and_belongs_to_many guessing of foreign key so that keys are generated correctly for models like SomeVerySpecialClient
|
5231
5244
|
[Florian Weber]
|
5232
5245
|
|
5233
5246
|
* Added counter_sql option for has_many associations [Jeremy Kemper]. Documentation:
|
@@ -5294,9 +5307,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5294
5307
|
|
5295
5308
|
fixtures/developers/fixtures.yaml
|
5296
5309
|
fixtures/accounts/fixtures.yaml
|
5297
|
-
|
5310
|
+
|
5298
5311
|
...you now need to do:
|
5299
|
-
|
5312
|
+
|
5300
5313
|
fixtures/developers.yaml
|
5301
5314
|
fixtures/accounts.yaml
|
5302
5315
|
|
@@ -5323,13 +5336,13 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5323
5336
|
name: David Heinemeier Hansson
|
5324
5337
|
birthday: 1979-10-15
|
5325
5338
|
profession: Systems development
|
5326
|
-
|
5339
|
+
|
5327
5340
|
steve:
|
5328
5341
|
id: 2
|
5329
5342
|
name: Steve Ross Kellock
|
5330
5343
|
birthday: 1974-09-27
|
5331
5344
|
profession: guy with keyboard
|
5332
|
-
|
5345
|
+
|
5333
5346
|
The change is NOT backwards compatible. Fixtures written in the old YAML style needs to be rewritten!
|
5334
5347
|
|
5335
5348
|
* All associations will now attempt to require the classes that they associate to. Relieving the need for most explicit 'require' statements.
|
@@ -5337,7 +5350,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5337
5350
|
|
5338
5351
|
*1.1.0* (34)
|
5339
5352
|
|
5340
|
-
* Added automatic fixture setup and instance variable availability. Fixtures can also be automatically
|
5353
|
+
* Added automatic fixture setup and instance variable availability. Fixtures can also be automatically
|
5341
5354
|
instantiated in instance variables relating to their names using the following style:
|
5342
5355
|
|
5343
5356
|
class FixturesTest < Test::Unit::TestCase
|
@@ -5354,10 +5367,10 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5354
5367
|
attributes. This is really useful when you have information that's only relevant to the join itself, such as a "added_on" column for an association
|
5355
5368
|
between post and category. The added attributes will automatically be injected into objects retrieved through the association similar to the piggy-back
|
5356
5369
|
approach:
|
5357
|
-
|
5370
|
+
|
5358
5371
|
post.categories.push_with_attributes(category, :added_on => Date.today)
|
5359
5372
|
post.categories.first.added_on # => Date.today
|
5360
|
-
|
5373
|
+
|
5361
5374
|
NOTE: The categories table doesn't have a added_on column, it's the categories_post join table that does!
|
5362
5375
|
|
5363
5376
|
* Fixed that :exclusively_dependent and :dependent can't be activated at the same time on has_many associations [Jeremy Kemper]
|
@@ -5410,8 +5423,8 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5410
5423
|
|
5411
5424
|
* Improved the speed of respond_to? by placing the dynamic methods lookup table in a hash [geech]
|
5412
5425
|
|
5413
|
-
* Added that any additional fields added to the join table in a has_and_belongs_to_many association
|
5414
|
-
will be placed as attributes when pulling records out through has_and_belongs_to_many associations.
|
5426
|
+
* Added that any additional fields added to the join table in a has_and_belongs_to_many association
|
5427
|
+
will be placed as attributes when pulling records out through has_and_belongs_to_many associations.
|
5415
5428
|
This is helpful when have information about the association itself that you want available on retrival.
|
5416
5429
|
|
5417
5430
|
* Added better loading exception catching and RubyGems retries to the database adapters [alexeyv]
|
@@ -5420,9 +5433,9 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5420
5433
|
|
5421
5434
|
* Fixed Base#transaction so that it returns the result of the last expression in the transaction block [alexeyv]
|
5422
5435
|
|
5423
|
-
* Added Fixture#find to find the record corresponding to the fixture id. The record
|
5436
|
+
* Added Fixture#find to find the record corresponding to the fixture id. The record
|
5424
5437
|
class name is guessed by using Inflector#classify (also new) on the fixture directory name.
|
5425
|
-
|
5438
|
+
|
5426
5439
|
Before: Document.find(@documents["first"]["id"])
|
5427
5440
|
After : @documents["first"].find
|
5428
5441
|
|
@@ -5432,7 +5445,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5432
5445
|
|
5433
5446
|
* Fixed quoting problems on SQLite by adding quote_string to the AbstractAdapter that can be overwritten by the concrete
|
5434
5447
|
adapters for a call to the dbm. [Andreas Schwarz]
|
5435
|
-
|
5448
|
+
|
5436
5449
|
* Removed RubyGems backup strategy for requiring SQLite-adapter -- if people want to use gems, they're already doing it with AR.
|
5437
5450
|
|
5438
5451
|
|
@@ -5448,19 +5461,19 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5448
5461
|
|
5449
5462
|
* Added serialize as a new class method to control when text attributes should be YAMLized or not. This means that automated
|
5450
5463
|
serialization of hashes, arrays, and so on WILL NO LONGER HAPPEN (#10). You need to do something like this:
|
5451
|
-
|
5464
|
+
|
5452
5465
|
class User < ActiveRecord::Base
|
5453
5466
|
serialize :settings
|
5454
5467
|
end
|
5455
|
-
|
5468
|
+
|
5456
5469
|
This will assume that settings is a text column and will now YAMLize any object put in that attribute. You can also specify
|
5457
5470
|
an optional :class_name option that'll raise an exception if a serialized object is retrieved as a descendant of a class not in
|
5458
5471
|
the hierarchy. Example:
|
5459
|
-
|
5472
|
+
|
5460
5473
|
class User < ActiveRecord::Base
|
5461
5474
|
serialize :settings, :class_name => "Hash"
|
5462
5475
|
end
|
5463
|
-
|
5476
|
+
|
5464
5477
|
user = User.create("settings" => %w( one two three ))
|
5465
5478
|
User.find(user.id).settings # => raises SerializationTypeMismatch
|
5466
5479
|
|
@@ -5475,7 +5488,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5475
5488
|
|
5476
5489
|
* Added the possibility to chain the return of what happened inside a logged block [geech]:
|
5477
5490
|
|
5478
|
-
This now works:
|
5491
|
+
This now works:
|
5479
5492
|
log { ... }.map { ... }
|
5480
5493
|
|
5481
5494
|
Instead of doing:
|
@@ -5485,7 +5498,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5485
5498
|
|
5486
5499
|
* Added "socket" option for the MySQL adapter, so you can change it to something else than "/tmp/mysql.sock" [Anna Lissa Cruz]
|
5487
5500
|
|
5488
|
-
* Added respond_to? answers for all the attribute methods. So if Person has a name attribute retrieved from the table schema,
|
5501
|
+
* Added respond_to? answers for all the attribute methods. So if Person has a name attribute retrieved from the table schema,
|
5489
5502
|
person.respond_to? "name" will return true.
|
5490
5503
|
|
5491
5504
|
* Added Base.benchmark which can be used to aggregate logging and benchmark, so you can measure and represent multiple statements in a single block.
|
@@ -5506,7 +5519,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5506
5519
|
* Added compatibility with 2.x series of sqlite-ruby drivers. [Jamis Buck]
|
5507
5520
|
|
5508
5521
|
* Added type safety for association assignments, so a ActiveRecord::AssociationTypeMismatch will be raised if you attempt to
|
5509
|
-
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
|
5522
|
+
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
|
5510
5523
|
mistaken association assignments. [Reported by Andreas Schwarz]
|
5511
5524
|
|
5512
5525
|
* Added the option to keep many fixtures in one single YAML document [what-a-day]
|
@@ -5518,7 +5531,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5518
5531
|
|
5519
5532
|
* Added the option to observer more than one class at the time by specifying observed_class as an array
|
5520
5533
|
|
5521
|
-
* Added auto-id propagation support for tables with arbitrary primary keys that have autogenerated sequences associated with them
|
5534
|
+
* Added auto-id propagation support for tables with arbitrary primary keys that have autogenerated sequences associated with them
|
5522
5535
|
on PostgreSQL. [Dave Steinberg]
|
5523
5536
|
|
5524
5537
|
* Changed that integer and floats set to "" through attributes= remain as NULL. This was especially a problem for scaffolding and postgresql. (#49)
|
@@ -5560,8 +5573,8 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5560
5573
|
directly from ActiveRecord. So if the hierarchy looks like: Reply < Message < ActiveRecord, then Message is used
|
5561
5574
|
to guess the table name from even when called on Reply. The guessing rules are as follows:
|
5562
5575
|
* Class name ends in "x", "ch" or "ss": "es" is appended, so a Search class becomes a searches table.
|
5563
|
-
* Class name ends in "y" preceded by a consonant or "qu": The "y" is replaced with "ies",
|
5564
|
-
so a Category class becomes a categories table.
|
5576
|
+
* Class name ends in "y" preceded by a consonant or "qu": The "y" is replaced with "ies",
|
5577
|
+
so a Category class becomes a categories table.
|
5565
5578
|
* Class name ends in "fe": The "fe" is replaced with "ves", so a Wife class becomes a wives table.
|
5566
5579
|
* Class name ends in "lf" or "rf": The "f" is replaced with "ves", so a Half class becomes a halves table.
|
5567
5580
|
* Class name ends in "person": The "person" is replaced with "people", so a Salesperson class becomes a salespeople table.
|
@@ -5574,14 +5587,14 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5574
5587
|
* Class name with word compositions: Compositions are underscored, so CreditCard class becomes a credit_cards table.
|
5575
5588
|
Additionally, the class-level table_name_prefix is prepended to the table_name and the table_name_suffix is appended.
|
5576
5589
|
So if you have "myapp_" as a prefix, the table name guess for an Account class becomes "myapp_accounts".
|
5577
|
-
|
5590
|
+
|
5578
5591
|
You can also overwrite this class method to allow for unguessable links, such as a Mouse class with a link to a
|
5579
5592
|
"mice" table. Example:
|
5580
|
-
|
5593
|
+
|
5581
5594
|
class Mouse < ActiveRecord::Base
|
5582
5595
|
def self.table_name() "mice" end
|
5583
5596
|
end
|
5584
|
-
|
5597
|
+
|
5585
5598
|
This conversion is now done through an external class called Inflector residing in lib/active_record/support/inflector.rb.
|
5586
5599
|
|
5587
5600
|
* Added find_all_in_collection to has_many defined collections. Works like this:
|
@@ -5589,7 +5602,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5589
5602
|
class Firm < ActiveRecord::Base
|
5590
5603
|
has_many :clients
|
5591
5604
|
end
|
5592
|
-
|
5605
|
+
|
5593
5606
|
firm.id # => 1
|
5594
5607
|
firm.find_all_in_clients "revenue > 1000" # SELECT * FROM clients WHERE firm_id = 1 AND revenue > 1000
|
5595
5608
|
|
@@ -5605,11 +5618,11 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5605
5618
|
errors.add_on_boundry_breaking "password", 3..20
|
5606
5619
|
end
|
5607
5620
|
end
|
5608
|
-
|
5621
|
+
|
5609
5622
|
This will add an error to the tune of "is too short (minimum is 3 characters)" or "is too long (minimum is 20 characters)" if
|
5610
5623
|
the password is outside the boundry. The messages can be changed by passing a third and forth parameter as message strings.
|
5611
5624
|
|
5612
|
-
* Implemented a clone method that works properly with AR. It returns a clone of the record that
|
5625
|
+
* Implemented a clone method that works properly with AR. It returns a clone of the record that
|
5613
5626
|
hasn't been assigned an id yet and is treated as a new record.
|
5614
5627
|
|
5615
5628
|
* Allow for domain sockets in PostgreSQL by not assuming localhost when no host is specified [Scott Barron]
|
@@ -5640,12 +5653,12 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5640
5653
|
|
5641
5654
|
*0.9.3*
|
5642
5655
|
|
5643
|
-
* Fixed bug with using a different primary key name together with has_and_belongs_to_many [Investigation by Scott]
|
5656
|
+
* Fixed bug with using a different primary key name together with has_and_belongs_to_many [Investigation by Scott]
|
5644
5657
|
|
5645
5658
|
* Added :exclusively_dependent option to the has_many association macro. The doc reads:
|
5646
5659
|
|
5647
5660
|
If set to true all the associated object are deleted in one SQL statement without having their
|
5648
|
-
before_destroy callback run. This should only be used on associations that depend solely on
|
5661
|
+
before_destroy callback run. This should only be used on associations that depend solely on
|
5649
5662
|
this class and don't need to do any clean-up in before_destroy. The upside is that it's much
|
5650
5663
|
faster, especially if there's a counter_cache involved.
|
5651
5664
|
|
@@ -5657,7 +5670,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5657
5670
|
|
5658
5671
|
* Fixed the use of floats (was broken since 0.9.0+)
|
5659
5672
|
|
5660
|
-
* Fixed PostgreSQL adapter so default values are displayed properly when used in conjunction with
|
5673
|
+
* Fixed PostgreSQL adapter so default values are displayed properly when used in conjunction with
|
5661
5674
|
Action Pack scaffolding.
|
5662
5675
|
|
5663
5676
|
* Fixed booleans support for PostgreSQL (use real true/false on boolean fields instead of 0/1 on tinyints) [radsaq]
|
@@ -5683,21 +5696,21 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5683
5696
|
class Event < ActiveRecord::Base
|
5684
5697
|
has_one_and_belongs_to_many :sponsors
|
5685
5698
|
end
|
5686
|
-
|
5699
|
+
|
5687
5700
|
class Sponsor < ActiveRecord::Base
|
5688
5701
|
has_one_and_belongs_to_many :sponsors
|
5689
5702
|
end
|
5690
5703
|
|
5691
5704
|
Earlier, you'd have to use synthetic methods for creating associations between two objects of the above class:
|
5692
|
-
|
5705
|
+
|
5693
5706
|
roskilde_festival.add_to_sponsors(carlsberg)
|
5694
5707
|
roskilde_festival.remove_from_sponsors(carlsberg)
|
5695
5708
|
|
5696
5709
|
nike.add_to_events(world_cup)
|
5697
5710
|
nike.remove_from_events(world_cup)
|
5698
|
-
|
5711
|
+
|
5699
5712
|
Now you can use regular array-styled methods:
|
5700
|
-
|
5713
|
+
|
5701
5714
|
roskilde_festival.sponsors << carlsberg
|
5702
5715
|
roskilde_festival.sponsors.delete(carlsberg)
|
5703
5716
|
|
@@ -5706,7 +5719,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5706
5719
|
|
5707
5720
|
* Added delete method for has_many associations. Using this will nullify an association between the has_many and the belonging
|
5708
5721
|
object by setting the foreign key to null. Consider this model:
|
5709
|
-
|
5722
|
+
|
5710
5723
|
class Post < ActiveRecord::Base
|
5711
5724
|
has_many :comments
|
5712
5725
|
end
|
@@ -5727,7 +5740,7 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5727
5740
|
* Active Record is now thread safe! (So you can use it with Cerise and WEBrick applications)
|
5728
5741
|
[Implementation idea by Michael Neumann, debugging assistance by Jamis Buck]
|
5729
5742
|
|
5730
|
-
* Improved performance by roughly 400% on a basic test case of pulling 100 records and querying one attribute.
|
5743
|
+
* Improved performance by roughly 400% on a basic test case of pulling 100 records and querying one attribute.
|
5731
5744
|
This brings the tax for using Active Record instead of "riding on the metal" (using MySQL-ruby C-driver directly) down to ~50%.
|
5732
5745
|
Done by doing lazy type conversions and caching column information on the class-level.
|
5733
5746
|
|
@@ -5744,46 +5757,46 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5744
5757
|
end
|
5745
5758
|
|
5746
5759
|
Iterating over 100 posts like this:
|
5747
|
-
|
5760
|
+
|
5748
5761
|
<% for post in @posts %>
|
5749
5762
|
<%= post.title %> has <%= post.comments_count %> comments
|
5750
5763
|
<% end %>
|
5751
|
-
|
5764
|
+
|
5752
5765
|
Will generate 100 SQL count queries -- one for each call to post.comments_count. If you instead add a "comments_count" int column
|
5753
5766
|
to the posts table and rewrite the comments association macro with:
|
5754
5767
|
|
5755
5768
|
class Comment < ActiveRecord::Base
|
5756
5769
|
belongs_to :post, :counter_cache => true
|
5757
5770
|
end
|
5758
|
-
|
5771
|
+
|
5759
5772
|
Those 100 SQL count queries will be reduced to zero. Beware that counter caching is only appropriate for objects that begin life
|
5760
5773
|
with the object it's specified to belong with and is destroyed like that as well. Typically objects where you would also specify
|
5761
5774
|
:dependent => true. If your objects switch from one belonging to another (like a post that can be move from one category to another),
|
5762
|
-
you'll have to manage the counter yourself.
|
5775
|
+
you'll have to manage the counter yourself.
|
5763
5776
|
|
5764
5777
|
* Added natural object-style assignment for has_one and belongs_to associations. Consider the following model:
|
5765
5778
|
|
5766
5779
|
class Project < ActiveRecord::Base
|
5767
5780
|
has_one :manager
|
5768
5781
|
end
|
5769
|
-
|
5782
|
+
|
5770
5783
|
class Manager < ActiveRecord::Base
|
5771
5784
|
belongs_to :project
|
5772
5785
|
end
|
5773
|
-
|
5786
|
+
|
5774
5787
|
Earlier, assignments would work like following regardless of which way the assignment told the best story:
|
5775
|
-
|
5788
|
+
|
5776
5789
|
active_record.manager_id = david.id
|
5777
|
-
|
5790
|
+
|
5778
5791
|
Now you can do it either from the belonging side:
|
5779
5792
|
|
5780
5793
|
david.project = active_record
|
5781
|
-
|
5794
|
+
|
5782
5795
|
...or from the having side:
|
5783
|
-
|
5796
|
+
|
5784
5797
|
active_record.manager = david
|
5785
|
-
|
5786
|
-
If the assignment happens from the having side, the assigned object is automatically saved. So in the example above, the
|
5798
|
+
|
5799
|
+
If the assignment happens from the having side, the assigned object is automatically saved. So in the example above, the
|
5787
5800
|
project_id attribute on david would be set to the id of active_record, then david would be saved.
|
5788
5801
|
|
5789
5802
|
* Added natural object-style assignment for has_many associations [Florian Weber]. Consider the following model:
|
@@ -5791,36 +5804,36 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5791
5804
|
class Project < ActiveRecord::Base
|
5792
5805
|
has_many :milestones
|
5793
5806
|
end
|
5794
|
-
|
5807
|
+
|
5795
5808
|
class Milestone < ActiveRecord::Base
|
5796
5809
|
belongs_to :project
|
5797
5810
|
end
|
5798
|
-
|
5811
|
+
|
5799
5812
|
Earlier, assignments would work like following regardless of which way the assignment told the best story:
|
5800
|
-
|
5813
|
+
|
5801
5814
|
deadline.project_id = active_record.id
|
5802
|
-
|
5815
|
+
|
5803
5816
|
Now you can do it either from the belonging side:
|
5804
5817
|
|
5805
5818
|
deadline.project = active_record
|
5806
|
-
|
5819
|
+
|
5807
5820
|
...or from the having side:
|
5808
|
-
|
5821
|
+
|
5809
5822
|
active_record.milestones << deadline
|
5810
|
-
|
5823
|
+
|
5811
5824
|
The milestone is automatically saved with the new foreign key.
|
5812
5825
|
|
5813
5826
|
* API CHANGE: Attributes for text (or blob or similar) columns will now have unknown classes stored using YAML instead of using
|
5814
5827
|
to_s. (Known classes that won't be yamelized are: String, NilClass, TrueClass, FalseClass, Fixnum, Date, and Time).
|
5815
5828
|
Likewise, data pulled out of text-based attributes will be attempted converged using Yaml if they have the "--- " header.
|
5816
5829
|
This was primarily done to be enable the storage of hashes and arrays without wrapping them in aggregations, so now you can do:
|
5817
|
-
|
5830
|
+
|
5818
5831
|
user = User.find(1)
|
5819
5832
|
user.preferences = { "background" => "black", "display" => large }
|
5820
5833
|
user.save
|
5821
|
-
|
5834
|
+
|
5822
5835
|
User.find(1).preferences # => { "background" => "black", "display" => large }
|
5823
|
-
|
5836
|
+
|
5824
5837
|
Please note that this method should only be used when you don't care about representing the object in proper columns in
|
5825
5838
|
the database. A money object consisting of an amount and a currency is still a much better fit for a value object done through
|
5826
5839
|
aggregations than this new option.
|
@@ -5828,14 +5841,14 @@ in effect. Added :readonly finder constraint. Calling an association collectio
|
|
5828
5841
|
* POSSIBLE CODE BREAKAGE: As a consequence of the lazy type conversions, it's a bad idea to reference the @attributes hash
|
5829
5842
|
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
|
5830
5843
|
new accessors for existing attributes, use read_attribute(attr_name) and write_attribute(attr_name, value) instead. Like this:
|
5831
|
-
|
5844
|
+
|
5832
5845
|
class Song < ActiveRecord::Base
|
5833
5846
|
# Uses an integer of seconds to hold the length of the song
|
5834
|
-
|
5847
|
+
|
5835
5848
|
def length=(minutes)
|
5836
5849
|
write_attribute("length", minutes * 60)
|
5837
5850
|
end
|
5838
|
-
|
5851
|
+
|
5839
5852
|
def length
|
5840
5853
|
read_attribute("length") / 60
|
5841
5854
|
end
|
@@ -5871,7 +5884,7 @@ _Misc_
|
|
5871
5884
|
# written_on (a date type) with Date.new("2004", "6", "24"). You can also specify a typecast character in the
|
5872
5885
|
# parenteses to have the parameters typecasted before they're used in the constructor. Use i for Fixnum, f for Float,
|
5873
5886
|
# s for String, and a for Array.
|
5874
|
-
|
5887
|
+
|
5875
5888
|
This is incredibly useful for assigning dates from HTML drop-downs of month, year, and day.
|
5876
5889
|
|
5877
5890
|
* Fixed bug with custom primary key column name and Base.find on multiple parameters.
|
@@ -5893,17 +5906,17 @@ _Transactions_
|
|
5893
5906
|
_Mapping_
|
5894
5907
|
|
5895
5908
|
* Added support for non-integer primary keys [Aredridel/earlier work by Michael Neumann]
|
5896
|
-
|
5909
|
+
|
5897
5910
|
User.find "jdoe"
|
5898
5911
|
Product.find "PDKEY-INT-12"
|
5899
5912
|
|
5900
5913
|
* Added option to specify naming method for primary key column. ActiveRecord::Base.primary_key_prefix_type can either
|
5901
5914
|
be set to nil, :table_name, or :table_name_with_underscore. :table_name will assume that Product class has a primary key
|
5902
5915
|
of "productid" and :table_name_with_underscore will assume "product_id". The default nil will just give "id".
|
5903
|
-
|
5904
|
-
* Added an overwriteable primary_key method that'll instruct AR to the name of the
|
5916
|
+
|
5917
|
+
* Added an overwriteable primary_key method that'll instruct AR to the name of the
|
5905
5918
|
id column [Aredridele/earlier work by Guan Yang]
|
5906
|
-
|
5919
|
+
|
5907
5920
|
class Project < ActiveRecord::Base
|
5908
5921
|
def self.primary_key() "project_id" end
|
5909
5922
|
end
|
@@ -5924,8 +5937,8 @@ _Mapping_
|
|
5924
5937
|
_Misc_
|
5925
5938
|
|
5926
5939
|
* Added freeze call to value object assignments to ensure they remain immutable [Spotted by Gavin Sinclair]
|
5927
|
-
|
5928
|
-
* Changed interface for specifying observed class in observers. Was OBSERVED_CLASS constant, now is
|
5940
|
+
|
5941
|
+
* Changed interface for specifying observed class in observers. Was OBSERVED_CLASS constant, now is
|
5929
5942
|
observed_class() class method. This is more consistant with things like self.table_name(). Works like this:
|
5930
5943
|
|
5931
5944
|
class AuditObserver < ActiveRecord::Observer
|
@@ -5952,20 +5965,20 @@ _Misc_
|
|
5952
5965
|
* Added inheritable callback queues that can ensure that certain callback methods or inline fragments are
|
5953
5966
|
run throughout the entire inheritance hierarchy. Regardless of whether a descendant overwrites the callback
|
5954
5967
|
method:
|
5955
|
-
|
5968
|
+
|
5956
5969
|
class Topic < ActiveRecord::Base
|
5957
5970
|
before_destroy :destroy_author, 'puts "I'm an inline fragment"'
|
5958
5971
|
end
|
5959
|
-
|
5972
|
+
|
5960
5973
|
Learn more in link:classes/ActiveRecord/Callbacks.html
|
5961
5974
|
|
5962
|
-
* Added :dependent option to has_many and has_one, which will automatically destroy associated objects when
|
5975
|
+
* Added :dependent option to has_many and has_one, which will automatically destroy associated objects when
|
5963
5976
|
the holder is destroyed:
|
5964
|
-
|
5977
|
+
|
5965
5978
|
class Album < ActiveRecord::Base
|
5966
5979
|
has_many :tracks, :dependent => true
|
5967
5980
|
end
|
5968
|
-
|
5981
|
+
|
5969
5982
|
All the associated tracks are destroyed when the album is.
|
5970
5983
|
|
5971
5984
|
* Added Base.create as a factory that'll create, save, and return a new object in one step.
|
@@ -5975,7 +5988,7 @@ _Misc_
|
|
5975
5988
|
|
5976
5989
|
* Fixed the install.rb to include simple.rb [Spotted by Kevin Bullock]
|
5977
5990
|
|
5978
|
-
* Modified block syntax to better follow our code standards outlined in
|
5991
|
+
* Modified block syntax to better follow our code standards outlined in
|
5979
5992
|
http://www.rubyonrails.org/CodingStandards
|
5980
5993
|
|
5981
5994
|
|
@@ -5986,7 +5999,7 @@ _Misc_
|
|
5986
5999
|
* Changed adapter-specific connection methods to use centralized ActiveRecord::Base.establish_connection,
|
5987
6000
|
which is parametized through a config hash with symbol keys instead of a regular parameter list.
|
5988
6001
|
This will allow for database connections to be opened in a more generic fashion. (Luke)
|
5989
|
-
|
6002
|
+
|
5990
6003
|
NOTE: This requires all *_connections to be updated! Read more in:
|
5991
6004
|
http://ar.rubyonrails.org/classes/ActiveRecord/Base.html#M000081
|
5992
6005
|
|
@@ -5995,7 +6008,7 @@ _Misc_
|
|
5995
6008
|
|
5996
6009
|
* Fixed SQLite adapter so dates are returned as Date objects, not Time objects [Spotted by Gavin Sinclair]
|
5997
6010
|
|
5998
|
-
* Fixed requirement of date class, so date conversions are succesful regardless of whether you
|
6011
|
+
* Fixed requirement of date class, so date conversions are succesful regardless of whether you
|
5999
6012
|
manually require date or not.
|
6000
6013
|
|
6001
6014
|
|
@@ -6003,10 +6016,10 @@ _Misc_
|
|
6003
6016
|
|
6004
6017
|
* Added transactions
|
6005
6018
|
|
6006
|
-
* Changed Base.find to also accept either a list (1, 5, 6) or an array of ids ([5, 7])
|
6019
|
+
* Changed Base.find to also accept either a list (1, 5, 6) or an array of ids ([5, 7])
|
6007
6020
|
as parameter and then return an array of objects instead of just an object
|
6008
6021
|
|
6009
|
-
* Fixed method has_collection? for has_and_belongs_to_many macro to behave as a
|
6022
|
+
* Fixed method has_collection? for has_and_belongs_to_many macro to behave as a
|
6010
6023
|
collection, not an association
|
6011
6024
|
|
6012
6025
|
* Fixed SQLite adapter so empty or nil values in columns of datetime, date, or time type
|