forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCHANGELOG
6543 lines (3804 loc) · 317 KB
/
CHANGELOG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*Rails 3.1.1 (unreleased)*
* Transactional fixtures enlist all active database connections. You can test
models on different connections without disabling transactional fixtures.
[Jeremy Kemper]
* Add deprecation for the preload_associations method. Fixes #3022.
[Jon Leighton]
* Don't require a DB connection when loading a model that uses set_primary_key. GH #2807.
[Jon Leighton]
* Fix using select() with a habtm association, e.g. Person.friends.select(:name). GH #3030 and
#2923.
[Hendy Tanata]
* Fix belongs_to polymorphic with custom primary key on target. GH #3104.
[Jon Leighton]
* CollectionProxy#replace should change the DB records rather than just mutating the array.
Fixes #3020.
[Jon Leighton]
* LRU cache in mysql and sqlite are now per-process caches.
* lib/active_record/connection_adapters/mysql_adapter.rb: LRU cache
keys are per process id.
* lib/active_record/connection_adapters/sqlite_adapter.rb: ditto
* Add first_or_create, first_or_create!, first_or_initialize methods to Active Record. This is a
better approach over the old find_or_create_by dynamic methods because it's clearer which
arguments are used to find the record and which are used to create it:
User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
[Andrés Mejía]
* Support bulk change_table in mysql2 adapter, as well as the mysql one. [Jon Leighton]
* If multiple parameters are sent representing a date, and some are blank, the
resulting object is nil. In previous releases those values defaulted to 1. This
only affects existing but blank parameters, missing ones still raise an error.
[Akira Matsuda]
* ActiveRecord::Base.establish_connection now takes a string that contains
a URI that specifies the connection configuration. For example:
ActiveRecord::Base.establish_connection 'postgres://localhost/foo'
* Active Record's dynamic finder will now raise the error if you passing in less number of arguments than what you call in method signature.
So if you were doing this and expecting the second argument to be nil:
User.find_by_username_and_group("sikachu")
You'll now get `ArgumentError: wrong number of arguments (1 for 2).` You'll then have to do this:
User.find_by_username_and_group("sikachu", nil)
[Prem Sichanugrist]
*Rails 3.1.0 (August 30, 2011)*
* Add a proxy_association method to association proxies, which can be called by association
extensions to access information about the association. This replaces proxy_owner etc with
proxy_association.owner.
[Jon Leighton]
* ActiveRecord::MacroReflection::AssociationReflection#build_record has a new method signature.
Before: def build_association(*options)
After: def build_association(*options, &block)
Users who are redefining this method to extend functionality should ensure that the block is
passed through to ActiveRecord::Base#new.
This change is necessary to fix https://github.com/rails/rails/issues/1842.
[Jon Leighton]
* AR#pluralize_table_names can be used to singularize/pluralize table name of an individual model:
class User < ActiveRecord::Base
self.pluralize_table_names = false
end
Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. [Guillermo Iguaran]
* Add block setting of attributes to singular associations:
class User < ActiveRecord::Base
has_one :account
end
user.build_account{ |a| a.credit_limit => 100.0 }
The block is called after the instance has been initialized. [Andrew White]
* Add ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or table does not exists. [Prem Sichanugrist]
* CSV Fixtures are deprecated and support will be removed in Rails 3.2.0
* AR#new, AR#create, AR#create!, AR#update_attributes and AR#update_attributes! all accept a second hash as option that allows you
to specify which role to consider when assigning attributes. This is built on top of ActiveModel's
new mass assignment capabilities:
class Post < ActiveRecord::Base
attr_accessible :title
attr_accessible :title, :published_at, :as => :admin
end
Post.new(params[:post], :as => :admin)
assign_attributes() with similar API was also added and attributes=(params, guard) was deprecated.
Please note that this changes the method signatures for AR#new, AR#create, AR#create!, AR#update_attributes and AR#update_attributes!. If you have overwritten these methods you should update them accordingly.
[Josh Kalderimis]
* default_scope can take a block, lambda, or any other object which responds to `call` for lazy
evaluation:
default_scope { ... }
default_scope lambda { ... }
default_scope method(:foo)
This feature was originally implemented by Tim Morgan, but was then removed in favour of
defining a 'default_scope' class method, but has now been added back in by Jon Leighton.
The relevant lighthouse ticket is #1812.
* Default scopes are now evaluated at the latest possible moment, to avoid problems where
scopes would be created which would implicitly contain the default scope, which would then
be impossible to get rid of via Model.unscoped.
Note that this means that if you are inspecting the internal structure of an
ActiveRecord::Relation, it will *not* contain the default scope, though the resulting
query will do. You can get a relation containing the default scope by calling
ActiveRecord#with_default_scope, though this is not part of the public API.
[Jon Leighton]
* If you wish to merge default scopes in special ways, it is recommended to define your default
scope as a class method and use the standard techniques for sharing code (inheritance, mixins,
etc.):
class Post < ActiveRecord::Base
def self.default_scope
where(:published => true).where(:hidden => false)
end
end
[Jon Leighton]
* PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
* ConnectionManagement middleware is changed to clean up the connection pool
after the rack body has been flushed.
* Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks.
It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of
the updated_at column. It should not be called on new records.
Example:
User.first.update_column(:name, "sebastian") # => true
[Sebastian Martinez]
* Associations with a :through option can now use *any* association as the
through or source association, including other associations which have a
:through option and has_and_belongs_to_many associations
[Jon Leighton]
* The configuration for the current database connection is now accessible via
ActiveRecord::Base.connection_config. [fxn]
* limits and offsets are removed from COUNT queries unless both are supplied.
For example:
People.limit(1).count # => 'SELECT COUNT(*) FROM people'
People.offset(1).count # => 'SELECT COUNT(*) FROM people'
People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
[lighthouse #6262]
* ActiveRecord::Associations::AssociationProxy has been split. There is now an Association class
(and subclasses) which are responsible for operating on associations, and then a separate,
thin wrapper called CollectionProxy, which proxies collection associations.
This prevents namespace pollution, separates concerns, and will allow further refactorings.
Singular associations (has_one, belongs_to) no longer have a proxy at all. They simply return
the associated record or nil. This means that you should not use undocumented methods such
as bob.mother.create - use bob.create_mother instead.
[Jon Leighton]
* Make has_many :through associations work correctly when you build a record and then save it. This
requires you to set the :inverse_of option on the source reflection on the join model, like so:
class Post < ActiveRecord::Base
has_many :taggings
has_many :tags, :through => :taggings
end
class Tagging < ActiveRecord::Base
belongs_to :post
belongs_to :tag, :inverse_of => :tagging # :inverse_of must be set!
end
class Tag < ActiveRecord::Base
has_many :taggings
has_many :posts, :through => :taggings
end
post = Post.first
tag = post.tags.build :name => "ruby"
tag.save # will save a Taggable linking to the post
[Jon Leighton]
* Support the :dependent option on has_many :through associations. For historical and practical
reasons, :delete_all is the default deletion strategy employed by association.delete(*records),
despite the fact that the default strategy is :nullify for regular has_many. Also, this only
works at all if the source reflection is a belongs_to. For other situations, you should directly
modify the through association.
[Jon Leighton]
* Changed the behaviour of association.destroy for has_and_belongs_to_many and has_many :through.
From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link',
not (necessarily) 'get rid of the associated records'.
Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It
would not delete any records in the join table. Now, it deletes the records in the join table.
Previously, has_many_through.destroy(*records) would destroy the records themselves, and the
records in the join table. [Note: This has not always been the case; previous version of Rails
only deleted the records themselves.] Now, it destroys only the records in the join table.
Note that this change is backwards-incompatible to an extent, but there is unfortunately no
way to 'deprecate' it before changing it. The change is being made in order to have
consistency as to the meaning of 'destroy' or 'delete' across the different types of associations.
If you wish to destroy the records themselves, you can do records.association.each(&:destroy)
[Jon Leighton]
* Add :bulk => true option to change_table to make all the schema changes defined in change_table block using a single ALTER statement. [Pratik Naik]
Example:
change_table(:users, :bulk => true) do |t|
t.string :company_name
t.change :birthdate, :datetime
end
This will now result in:
ALTER TABLE `users` ADD COLUMN `company_name` varchar(255), CHANGE `updated_at` `updated_at` datetime DEFAULT NULL
* Removed support for accessing attributes on a has_and_belongs_to_many join table. This has been
documented as deprecated behaviour since April 2006. Please use has_many :through instead.
[Jon Leighton]
* Added a create_association! method for has_one and belongs_to associations. [Jon Leighton]
* Migration files generated from model and constructive migration generators
(for example, add_name_to_users) use the reversible migration's `change`
method instead of the ordinary `up` and `down` methods. [Prem Sichanugrist]
* Removed support for interpolating string SQL conditions on associations. Instead, you should
use a proc, like so:
Before:
has_many :things, :conditions => 'foo = #{bar}'
After:
has_many :things, :conditions => proc { "foo = #{bar}" }
Inside the proc, 'self' is the object which is the owner of the association, unless you are
eager loading the association, in which case 'self' is the class which the association is within.
You can have any "normal" conditions inside the proc, so the following will work too:
has_many :things, :conditions => proc { ["foo = ?", bar] }
Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call
'record' to get the record being inserted or deleted. This is now passed as an argument to
the proc.
* Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting [DHH]. Example:
# Schema: User(name:string, password_digest:string, password_salt:string)
class User < ActiveRecord::Base
has_secure_password
end
user = User.new(:name => "david", :password => "", :password_confirmation => "nomatch")
user.save # => false, password required
user.password = "mUc3m00RsqyRe"
user.save # => false, confirmation doesn't match
user.password_confirmation = "mUc3m00RsqyRe"
user.save # => true
user.authenticate("notright") # => false
user.authenticate("mUc3m00RsqyRe") # => user
User.find_by_name("david").try(:authenticate, "notright") # => nil
User.find_by_name("david").try(:authenticate, "mUc3m00RsqyRe") # => user
* When a model is generated add_index is added by default for belongs_to or references columns
rails g model post user:belongs_to will generate the following:
class CreatePosts < ActiveRecord::Migration
def up
create_table :posts do |t|
t.belongs_to :user
t.timestamps
end
add_index :posts, :user_id
end
def down
drop_table :posts
end
end
[Santiago Pastorino]
* Setting the id of a belongs_to object will update the reference to the
object. [#2989 state:resolved]
* ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed
to closer match normal Ruby dup and clone semantics.
* Calling ActiveRecord::Base#clone will result in a shallow copy of the record,
including copying the frozen state. No callbacks will be called.
* Calling ActiveRecord::Base#dup will duplicate the record, including calling
after initialize hooks. Frozen state will not be copied, and all associations
will be cleared. A duped record will return true for new_record?, have a nil
id field, and is saveable.
* Migrations can be defined as reversible, meaning that the migration system
will figure out how to reverse your migration. To use reversible migrations,
just define the "change" method. For example:
class MyMigration < ActiveRecord::Migration
def change
create_table(:horses) do
t.column :content, :text
t.column :remind_at, :datetime
end
end
end
Some things cannot be automatically reversed for you. If you know how to
reverse those things, you should define 'up' and 'down' in your migration. If
you define something in `change` that cannot be reversed, an
IrreversibleMigration exception will be raised when going down.
* Migrations should use instance methods rather than class methods:
class FooMigration < ActiveRecord::Migration
def up
...
end
end
[Aaron Patterson]
* has_one maintains the association with separate after_create/after_update instead
of a single after_save. [fxn]
* The following code:
Model.limit(10).scoping { Model.count }
now generates the following SQL:
SELECT COUNT(*) FROM models LIMIT 10
This may not return what you want. Instead, you may with to do something
like this:
Model.limit(10).scoping { Model.all.size }
[Aaron Patterson]
*Rails 3.0.7 (April 18, 2011)*
* Destroying records via nested attributes works independent of reject_if LH #6006 [Durran Jordan]
* Delegate any? and many? to Model.scoped for consistency [Andrew White]
* Quote the ORDER BY clause in batched finds - fixes #6620 [Andrew White]
* Change exists? so records are not instantiated - fixes #6127. This prevents after_find
and after_initialize callbacks being triggered when checking for record existence.
[Andrew White]
* Fix performance bug with attribute accessors which only occurred on Ruby 1.8.7, and ensure we
cache type-casted values when the column returned from the db contains non-standard chars.
[Jon Leighton]
* Fix a performance regression introduced here 86acbf1cc050c8fa8c74a10c735e467fb6fd7df8
related to read_attribute method [Stian Grytøyr]
*Rails 3.0.6 (April 5, 2011)*
* Un-deprecate reorder method [Sebastian Martinez]
* Extensions are applied when calling +except+ or +only+ on relations.
Thanks to Iain Hecker.
* Schemas set in set_table_name are respected by the mysql adapter. LH #5322
* Fixed a bug when empty? was called on a grouped Relation that wasn't loaded.
LH #5829
* Reapply extensions when using except and only. Thanks Iain Hecker.
* Binary data is escaped when being inserted to SQLite3 Databases. Thanks
Naruse!
*Rails 3.0.5 (February 26, 2011)*
* Model.where(:column => 1).where(:column => 2) will always produce an AND
query.
[Aaron Patterson]
* Deprecated support for interpolated association conditions in the form of :conditions => 'foo = #{bar}'.
Instead, you should use a proc, like so:
Before:
has_many :things, :conditions => 'foo = #{bar}'
After:
has_many :things, :conditions => proc { "foo = #{bar}" }
Inside the proc, 'self' is the object which is the owner of the association, unless you are
eager loading the association, in which case 'self' is the class which the association is within.
You can have any "normal" conditions inside the proc, so the following will work too:
has_many :things, :conditions => proc { ["foo = ?", bar] }
Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call
'record' to get the record being inserted or deleted. This is now passed as an argument to
the proc.
[Jon Leighton]
*Rails 3.0.4 (February 8, 2011)*
* Added deprecation warning for has_and_belongs_to_many associations where the join table has
additional attributes other than the keys. Access to these attributes is removed in 3.1.
Please use has_many :through instead. [Jon Leighton]
*Rails 3.0.3 (November 16, 2010)*
* Support find by class like this: Post.where(:name => Post)
*Rails 3.0.2 (November 15, 2010)*
* Dramatic speed increase (see: http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/) [Aaron Patterson]
* reorder is deprecated in favor of except(:order).order(...) [Santiago Pastorino]
* except is now AR public API
Model.order('name').except(:order).order('salary')
generates:
SELECT * FROM models ORDER BY salary
[Santiago Pastorino]
* The following code:
Model.limit(10).scoping { Model.count }
now generates the following SQL:
SELECT COUNT(*) FROM models LIMIT 10
This may not return what you want. Instead, you may with to do something
like this:
Model.limit(10).scoping { Model.all.size }
[Aaron Patterson]
*Rails 3.0.1 (October 15, 2010)*
* Introduce a fix for CVE-2010-3993
*Rails 3.0.0 (August 29, 2010)*
* Changed update_attribute to not run callbacks and update the record directly in the database [Neeraj Singh]
* Add scoping and unscoped as the syntax to replace the old with_scope and with_exclusive_scope [José Valim]
* New rake task, db:migrate:status, displays status of migrations #4947 [Kevin Skoglund]
* select and order for ActiveRecord now always concatenate nested calls. Use reorder if you want the original order to be overwritten [Santiago Pastorino]
* PostgreSQL: ensure the database time zone matches Ruby's time zone #4895 [Aaron Patterson]
* Fixed that ActiveRecord::Base.compute_type would swallow NoMethodError #4751 [Andrew Bloomgarden, Andrew White]
* Add index length support for MySQL. #1852 [Emili Parreno, Pratik Naik]
Example:
add_index(:accounts, :name, :name => 'by_name', :length => 10)
=> CREATE INDEX by_name ON accounts(name(10))
add_index(:accounts, [:name, :surname], :name => 'by_name_surname', :length => {:name => 10, :surname => 15})
=> CREATE INDEX by_name_surname ON accounts(name(10), surname(15))
* find_or_create_by_attr(value, ...) works when attr is protected. #4457 [Santiago Pastorino, Marc-André Lafortune]
* New callbacks: after_commit and after_rollback. Do expensive operations like image thumbnailing after_commit instead of after_save. #2991 [Brian Durand]
* Serialized attributes are not converted to YAML if they are any of the formats that can be serialized to XML (like Hash, Array and Strings). [José Valim]
* Destroy uses optimistic locking. If lock_version on the record you're destroying doesn't match lock_version in the database, a StaleObjectError is raised. #1966 [Curtis Hawthorne]
* PostgreSQL: drop support for old postgres driver. Use pg 0.9.0 or later. [Jeremy Kemper]
* Observers can prevent records from saving by returning false, just like before_save and friends. #4087 [Mislav Marohnić]
* Add Relation extensions. [Pratik Naik]
users = User.where(:admin => true).extending(User::AdminPowers)
latest_users = User.order('created_at DESC') do
def posts_count
Post.count(:user_id => to_a.map(&:id))
end
end
* To prefix the table names of all models in a module, define self.table_name_prefix on the module. #4032 [Andrew White]
* Silenced "SHOW FIELDS" and "SET SQL_AUTO_IS_NULL=0" statements from the MySQL driver to improve log signal to noise ration in development [DHH]
* PostgreSQLAdapter: set time_zone to UTC when Base.default_timezone == :utc so that Postgres doesn't incorrectly offset-adjust values inserted into TIMESTAMP WITH TIME ZONE columns. #3777 [Jack Christensen]
* Allow relations to be used as scope.
class Item
scope :red, where(:colour => 'red')
end
Item.red.limit(10) # Ten red items
* Rename named_scope to scope. [Pratik Naik]
* Changed ActiveRecord::Base.store_full_sti_class to be true by default reflecting the previously announced Rails 3 default [DHH]
* Add Relation#except. [Pratik Naik]
one_red_item = Item.where(:colour => 'red').limit(1)
all_items = one_red_item.except(:where, :limit)
* Add Relation#delete_all. [Pratik Naik]
Item.where(:colour => 'red').delete_all
* Add Model.having and Relation#having. [Pratik Naik]
Developer.group("salary").having("sum(salary) > 10000").select("salary")
* Add Relation#count. [Pratik Naik]
legends = People.where("age > 100")
legends.count
legends.count(:age, :distinct => true)
legends.select('id').count
* Add Model.readonly and association_collection#readonly finder method. [Pratik Naik]
Post.readonly.to_a # Load all posts in readonly mode
@user.items.readonly(false).to_a # Load all the user items in writable mode
* Add .lock finder method [Pratik Naik]
User.lock.where(:name => 'lifo').to_a
old_items = Item.where("age > 100")
old_items.lock.each {|i| .. }
* Add Model.from and association_collection#from finder methods [Pratik Naik]
user = User.scoped
user.select('*').from('users, items')
* Add relation.destroy_all [Pratik Naik]
old_items = Item.where("age > 100")
old_items.destroy_all
* Add relation.exists? [Pratik Naik]
red_items = Item.where(:colours => 'red')
red_items.exists?
red_items.exists?(1)
* Add find(ids) to relations. [Pratik Naik]
old_users = User.order("age DESC")
old_users.find(1)
old_users.find(1, 2, 3)
* Add new finder methods to association collection. [Pratik Naik]
class User < ActiveRecord::Base
has_many :items
end
user = User.first
user.items.where(:items => {:colour => 'red'})
user.items.select('items.id')
* Add relation.reload to force reloading the records. [Pratik Naik]
topics = Topic.scoped
topics.to_a # force load
topics.first # returns a cached record
topics.reload
topics.first # Fetches a new record from the database
* Rename Model.conditions and relation.conditions to .where. [Pratik Naik]
Before :
User.conditions(:name => 'lifo')
User.select('id').conditions(["age > ?", 21])
Now :
User.where(:name => 'lifo')
User.select('id').where(["age > ?", 21])
* Add Model.select/group/order/limit/joins/conditions/preload/eager_load class methods returning a lazy relation. [Pratik Naik]
Examples :
posts = Post.select('id).order('name') # Returns a lazy relation
posts.each {|p| puts p.id } # Fires "select id from posts order by name"
* Model.scoped now returns a relation if invoked without any arguments. [Pratik Naik]
Example :
posts = Post.scoped
posts.size # Fires "select count(*) from posts" and returns the count
posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects
* Association inverses for belongs_to, has_one, and has_many. Optimization to reduce database queries. #3533 [Murray Steele]
# post.comments sets each comment's post without needing to :include
class Post < ActiveRecord::Base
has_many :comments, :inverse_of => :post
end
* MySQL: add_ and change_column support positioning. #3286 [Ben Marini]
* Reset your Active Record counter caches with the reset_counter_cache class method. #1211 [Mike Breen, Gabe da Silveira]
* Remove support for SQLite 2. Please upgrade to SQLite 3+ or install the plugin from git://github.com/rails/sqlite2_adapter.git [Pratik Naik]
* PostgreSQL: XML datatype support. #1874 [Leonardo Borges]
* quoted_date converts time-like objects to ActiveRecord::Base.default_timezone before serialization. This allows you to use Time.now in find conditions and have it correctly be serialized as the current time in UTC when default_timezone == :utc. #2946 [Geoff Buesing]
* SQLite: drop support for 'dbfile' option in favor of 'database.' #2363 [Paul Hinze, Jeremy Kemper]
* Added :primary_key option to belongs_to associations. #765 [Szymon Nowak, Philip Hallstrom, Noel Rocha]
# employees.company_name references companies.name
Employee.belongs_to :company, :primary_key => 'name', :foreign_key => 'company_name'
* Implement #many? for NamedScope and AssociationCollection using #size. #1500 [Chris Kampmeier]
* Added :touch option to belongs_to associations that will touch the parent record when the current record is saved or destroyed [DHH]
* Added ActiveRecord::Base#touch to update the updated_at/on attributes (or another specified timestamp) with the current time [DHH]
*2.3.2 [Final] (March 15, 2009)*
* Added ActiveRecord::Base.find_each and ActiveRecord::Base.find_in_batches for batch processing [DHH/Jamis Buck]
* Added that ActiveRecord::Base.exists? can be called with no arguments #1817 [Scott Taylor]
* Add Support for updating deeply nested models from a single form. #1202 [Eloy Duran]
class Book < ActiveRecord::Base
has_one :author
has_many :pages
accepts_nested_attributes_for :author, :pages
end
* Make after_save callbacks fire only if the record was successfully saved. #1735 [Michael Lovitt]
Previously the callbacks would fire if a before_save cancelled saving.
* Support nested transactions using database savepoints. #383 [Jonathan Viney, Hongli Lai]
* Added dynamic scopes ala dynamic finders #1648 [Yaroslav Markin]
* Fixed that ActiveRecord::Base#new_record? should return false (not nil) for existing records #1219 [Yaroslav Markin]
* I18n the word separator for error messages. Introduces the activerecord.errors.format.separator translation key. #1294 [Akira Matsuda]
* Add :having as a key to find and the relevant associations. [Emilio Tagua]
* Added default_scope to Base #1381 [Paweł Kondzior]. Example:
class Person < ActiveRecord::Base
default_scope :order => 'last_name, first_name'
end
class Company < ActiveRecord::Base
has_many :people
end
Person.all # => Person.find(:all, :order => 'last_name, first_name')
Company.find(1).people # => Person.find(:all, :order => 'last_name, first_name', :conditions => { :company_id => 1 })
*2.2.1 [RC2] (November 14th, 2008)*
* Ensure indices don't flip order in schema.rb #1266 [Jordi Bunster]
* Fixed that serialized strings should never be type-casted (i.e. turning "Yes" to a boolean) #857 [Andreas Korth]
*2.2.0 [RC1] (October 24th, 2008)*
* Skip collection ids reader optimization if using :finder_sql [Jeremy Kemper]
* Add Model#delete instance method, similar to Model.delete class method. #1086 [Hongli Lai (Phusion)]
* MySQL: cope with quirky default values for not-null text columns. #1043 [Frederick Cheung]
* Multiparameter attributes skip time zone conversion for time-only columns [#1030 state:resolved] [Geoff Buesing]
* Base.skip_time_zone_conversion_for_attributes uses class_inheritable_accessor, so that subclasses don't overwrite Base [#346 state:resolved] [Emilio Tagua]
* Added find_last_by dynamic finder #762 [Emilio Tagua]
* Internal API: configurable association options and build_association method for reflections so plugins may extend and override. #985 [Hongli Lai (Phusion)]
* Changed benchmarks to be reported in milliseconds [David Heinemeier Hansson]
* Connection pooling. #936 [Nick Sieger]
* Merge scoped :joins together instead of overwriting them. May expose scoping bugs in your code! #501 [Andrew White]
* before_save, before_validation and before_destroy callbacks that return false will now ROLLBACK the transaction. Previously this would have been committed before the processing was aborted. #891 [Xavier Noria]
* Transactional migrations for databases which support them. #834 [divoxx, Adam Wiggins, Tarmo Tänav]
* Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. #446. [Andrew Stone, Nik Wakelin]
* change_column_default preserves the not-null constraint. #617 [Tarmo Tänav]
* Fixed that create database statements would always include "DEFAULT NULL" (Nick Sieger) [#334]
* Add :tokenizer option to validates_length_of to specify how to split up the attribute string. #507. [David Lowenfels] Example :
# Ensure essay contains at least 100 words.
validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least %d words."), :tokenizer => lambda {|str| str.scan(/\w+/) }
* Allow conditions on multiple tables to be specified using hash. [Pratik Naik]. Example:
User.all :joins => :items, :conditions => { :age => 10, :items => { :color => 'black' } }
Item.first :conditions => { :items => { :color => 'red' } }
* Always treat integer :limit as byte length. #420 [Tarmo Tänav]
* Partial updates don't update lock_version if nothing changed. #426 [Daniel Morrison]
* Fix column collision with named_scope and :joins. #46 [Duncan Beevers, Mark Catley]
* db:migrate:down and :up update schema_migrations. #369 [Michael Raidel, RaceCondition]
* PostgreSQL: support :conditions => [':foo::integer', { :foo => 1 }] without treating the ::integer typecast as a bind variable. [Tarmo Tänav]
* MySQL: rename_column preserves column defaults. #466 [Diego Algorta]
* Add :from option to calculations. #397 [Ben Munat]
* Add :validate option to associations to enable/disable the automatic validation of associated models. Resolves #301. [Jan De Poorter]
* PostgreSQL: use 'INSERT ... RETURNING id' for 8.2 and later. [Jeremy Kemper]
* Added SQL escaping for :limit and :offset in MySQL [Jonathan Wiess]
*2.1.0 (May 31st, 2008)*
* Add ActiveRecord::Base.sti_name that checks ActiveRecord::Base#store_full_sti_class? and returns either the full or demodulized name. [Rick Olson]
* Add first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
* Added SQL escaping for :limit and :offset #288 [Aaron Bedra, Steven Bristol, Jonathan Wiess]
* Added first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
* Ensure hm:t preloading honours reflection options. Resolves #137. [Frederick Cheung]
* Added protection against duplicate migration names (Aslak Hellesøy) [#112]
* Base#instantiate_time_object: eliminate check for Time.zone, since we can assume this is set if time_zone_aware_attributes is set to true [Geoff Buesing]
* Time zone aware attribute methods use Time.zone.parse instead of #to_time for String arguments, so that offset information in String is respected. Resolves #105. [Scott Fleckenstein, Geoff Buesing]
* Added change_table for migrations (Jeff Dean) [#71]. Example:
change_table :videos do |t|
t.timestamps # adds created_at, updated_at
t.belongs_to :goat # adds goat_id integer
t.string :name, :email, :limit => 20 # adds name and email both with a 20 char limit
t.remove :name, :email # removes the name and email columns
end
* Fixed has_many :through .create with no parameters caused a "can't dup NilClass" error (Steven Soroka) [#85]
* Added block-setting of attributes for Base.create like Base.new already has (Adam Meehan) [#39]
* Fixed that pessimistic locking you reference the quoted table name (Josh Susser) [#67]
* Fixed that change_column should be able to use :null => true on a field that formerly had false [Nate Wiger] [#26]
* Added that the MySQL adapter should map integer to either smallint, int, or bigint depending on the :limit just like PostgreSQL [David Heinemeier Hansson]
* Change validates_uniqueness_of :case_sensitive option default back to true (from [9160]). Love your database columns, don't LOWER them. [Rick Olson]
* Add support for interleaving migrations by storing which migrations have run in the new schema_migrations table. Closes #11493 [Jordi Bunster]
* ActiveRecord::Base#sum defaults to 0 if no rows are returned. Closes #11550 [Kamal Fariz Mahyuddin]
* Ensure that respond_to? considers dynamic finder methods. Closes #11538. [James Mead]
* Ensure that save on parent object fails for invalid has_one association. Closes #10518. [Pratik Naik]
* Remove duplicate code from associations. [Pratik Naik]
* Refactor HasManyThroughAssociation to inherit from HasManyAssociation. Association callbacks and <association>_ids= now work with hm:t. #11516 [Ruy Asan]
* Ensure HABTM#create and HABTM#build do not load entire association. [Pratik Naik]
* Improve documentation. [Xavier Noria, Jack Danger Canty, leethal]
* Tweak ActiveRecord::Base#to_json to include a root value in the returned hash: {"post": {"title": ...}} [Rick Olson]
Post.find(1).to_json # => {"title": ...}
config.active_record.include_root_in_json = true
Post.find(1).to_json # => {"post": {"title": ...}}
* Add efficient #include? to AssociationCollection (for has_many/has_many :through/habtm). [stopdropandrew]
* PostgreSQL: create_ and drop_database support. #9042 [ez, pedz, Nick Sieger]
* Ensure that validates_uniqueness_of works with with_scope. Closes #9235. [Nik Wakelin, cavalle]
* Partial updates include only unsaved attributes. Off by default; set YourClass.partial_updates = true to enable. [Jeremy Kemper]
* Removing unnecessary uses_tzinfo helper from tests, given that TZInfo is now bundled [Geoff Buesing]
* Fixed that validates_size_of :within works in associations #11295, #10019 [cavalle]
* Track changes to unsaved attributes. [Jeremy Kemper]
* Switched to UTC-timebased version numbers for migrations and the schema. This will as good as eliminate the problem of multiple migrations getting the same version assigned in different branches. Also added rake db:migrate:up/down to apply individual migrations that may need to be run when you merge branches #11458 [John Barnette]
* Fixed that has_many :through would ignore the hash conditions #11447 [Emilio Tagua]
* Fix issue where the :uniq option of a has_many :through association is ignored when find(:all) is called. Closes #9407 [cavalle]
* Fix duplicate table alias error when including an association with a has_many :through association on the same join table. Closes #7310 [cavalle]
* More efficient association preloading code that compacts a through_records array in a central location. Closes #11427 [Jack Danger Canty]
* Improve documentation. [Ryan Bigg, Jan De Poorter, Cheah Chu Yeow, Xavier Shay, Jack Danger Canty, Emilio Tagua, Xavier Noria, Sunny Ripert]
* Fixed that ActiveRecord#Base.find_or_create/initialize would not honor attr_protected/accessible when used with a hash #11422 [Emilio Tagua]
* Added ActiveRecord#Base.all/first/last as aliases for find(:all/:first/:last) #11413 [nkallen, Chris O'Sullivan]
* Merge the has_finder gem, renamed as 'named_scope'. #11404 [nkallen]
class Article < ActiveRecord::Base
named_scope :published, :conditions => {:published => true}
named_scope :popular, :conditions => ...
end
Article.published.paginate(:page => 1)
Article.published.popular.count
Article.popular.find(:first)
Article.popular.find(:all, :conditions => {...})
See http://pivots.pivotallabs.com/users/nick/blog/articles/284-hasfinder-it-s-now-easier-than-ever-to-create-complex-re-usable-sql-queries
* Add has_one :through support. #4756 [Chris O'Sullivan]
* Migrations: create_table supports primary_key_prefix_type. #10314 [student, Chris O'Sullivan]
* Added logging for dependency load errors with fixtures #11056 [stuthulhu]
* Time zone aware attributes use Time#in_time_zone [Geoff Buesing]
* Fixed that scoped joins would not always be respected #6821 [Theory/Jack Danger Canty]
* Ensure that ActiveRecord::Calculations disambiguates field names with the table name. #11027 [cavalle]
* Added add/remove_timestamps to the schema statements for adding the created_at/updated_at columns on existing tables #11129 [jramirez]
* Added ActiveRecord::Base.find(:last) #11338 [Emilio Tagua]
* test_native_types expects DateTime.local_offset instead of DateTime.now.offset; fixes test breakage due to dst transition [Geoff Buesing]
* Add :readonly option to HasManyThrough associations. #11156 [Emilio Tagua]
* Improve performance on :include/:conditions/:limit queries by selectively joining in the pre-query. #9560 [dasil003]
* Perf fix: Avoid the use of named block arguments. Closes #11109 [adymo]
* PostgreSQL: support server versions 7.4 through 8.0 and the ruby-pg driver. #11127 [jdavis]
* Ensure association preloading doesn't break when an association returns nil. ##11145 [GMFlash]
* Make dynamic finders respect the :include on HasManyThrough associations. #10998. [cpytel]
* Base#instantiate_time_object only uses Time.zone when Base.time_zone_aware_attributes is true; leverages Time#time_with_datetime_fallback for readability [Geoff Buesing]
* Refactor ConnectionAdapters::Column.new_time: leverage DateTime failover behavior of Time#time_with_datetime_fallback [Geoff Buesing]
* Improve associations performance by using symbol callbacks instead of string callbacks. #11108 [adymo]
* Optimise the BigDecimal conversion code. #11110 [adymo]
* Introduce the :readonly option to all associations. Records from the association cannot be saved. #11084 [Emilio Tagua]
* Multiparameter attributes for time columns fail over to DateTime when out of range of Time [Geoff Buesing]
* Base#instantiate_time_object uses Time.zone.local() [Geoff Buesing]
* Add timezone-aware attribute readers and writers. #10982 [Geoff Buesing]
* Instantiating time objects in multiparameter attributes uses Time.zone if available. #10982 [Rick Olson]
* Add note about how ActiveRecord::Observer classes are initialized in a Rails app. #10980 [Xavier Noria]
* MySQL: omit text/blob defaults from the schema instead of using an empty string. #10963 [mdeiters]
* belongs_to supports :dependent => :destroy and :delete. #10592 [Jonathan Viney]
* Introduce preload query strategy for eager :includes. #9640 [Frederick Cheung, Aliaksey Kandratsenka, codafoo]
* Support aggregations in finder conditions. #10572 [Ryan Kinderman]
* Organize and clean up the Active Record test suite. #10742 [John Barnette]
* Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]
* Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu]
* Fixtures: removed support for the ancient pre-YAML file format. #10736 [John Barnette]
* More thoroughly quote table names. #10698 [dimdenis, lotswholetime, Jeremy Kemper]
* update_all ignores scoped :order and :limit, so post.comments.update_all doesn't try to include the comment order in the update statement. #10686 [Brendan Ribera]
* Added ActiveRecord::Base.cache_key to make it easier to cache Active Records in combination with the new ActiveSupport::Cache::* libraries [David Heinemeier Hansson]