Permalink
Browse files

Add some doc for ActiveRecord::Model

  • Loading branch information...
1 parent b236f08 commit 00318e9bdfc346a57cab34b2ec3724f3e9605ac1 @jonleighton jonleighton committed Dec 24, 2011
Showing with 38 additions and 3 deletions.
  1. +31 −3 activerecord/CHANGELOG.md
  2. +7 −0 activerecord/lib/active_record/model.rb
View
@@ -1,5 +1,33 @@
## Rails 4.0.0 (unreleased) ##
+* Added the `ActiveRecord::Model` module which can be included in a
+ class as an alternative to inheriting from `ActiveRecord::Base`:
+
+ class Post
+ include ActiveRecord::Model
+ end
+
+ Please note:
+
+ * Up until now it has been safe to assume that all AR models are
+ descendants of `ActiveRecord::Base`. This is no longer a safe
+ assumption, but it may transpire that there are areas of the
+ code which still make this assumption. So there may be
+ 'teething difficulties' with this feature. (But please do try it
+ and report bugs.)
+
+ * Plugins & libraries etc that add methods to `ActiveRecord::Base`
+ will not be compatible with `ActiveRecord::Model`. Those libraries
+ should add to `ActiveRecord::Model` instead (which is included in
+ `Base`), or better still, avoid monkey-patching AR and instead
+ provide a module that users can include where they need it.
+
+ * To minimise the risk of conflicts with other code, it is
+ advisable to include `ActiveRecord::Model` early in your class
+ definition.
+
+ *Jon Leighton*
+
* PostgreSQL hstore records can be created.
* PostgreSQL hstore types are automatically deserialized from the database.
@@ -36,7 +64,7 @@
* Implemented ActiveRecord::Relation#pluck method
Method returns Array of column value from table under ActiveRecord model
-
+
Client.pluck(:id)
*Bogdan Gusiev*
@@ -53,7 +81,7 @@
Post.find(1)
Post.connection.close
}.join
-
+
Only people who spawn threads in their application code need to worry
about this change.
@@ -152,7 +180,7 @@
during :reject_if => :all_blank (fixes #2937)
*Aaron Christy*
-
+
## Rails 3.1.3 (unreleased) ##
* Perf fix: If we're deleting all records in an association, don't add a IN(..) clause
@@ -1,6 +1,13 @@
require 'active_support/deprecation'
module ActiveRecord
+ # <tt>ActiveRecord::Model</tt> can be included into a class to add Active Record persistence.
+ # This is an alternative to inheriting from <tt>ActiveRecord::Base</tt>. Example:
+ #
+ # class Post
+ # include ActiveRecord::Model
+ # end
+ #
module Model
# So we can recognise an AR class even while self.included is being
# executed. (At that time, klass < Model == false.)

6 comments on commit 00318e9

kris commented on 00318e9 Dec 24, 2011

I like the way this sounds so far.

Nice stuff !!

looks interesting. Is this change because it's considered a more proper way to do things or are there serious issues inheriting from ActiveRecord::Base?

Contributor

jingweno replied Dec 24, 2011

Thanks for doing this. It's one big step forward! But still, ActiveRecord model knows about persistency. Would changes like this on the horizontal? http://martinfowler.com/eaaCatalog/dataMapper.html

This is great news, I've always disliked how domain objects needed to inherit from ActiveRecord.

Contributor

jingweno replied Jan 11, 2012

Did u guys read about DataMapper 2.0? http://solnic.eu/2012/01/10/ruby-datamapper-status.html. I think that's what really makes sense - separating Domain Object with the persistent layer.

Please sign in to comment.