In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
|
|
||
| module ActiveRecord | ||
| module ConnectionHandling | ||
| # Establishes the connection to the database. Accepts a hash as input where | ||
27 comments
on commit 9e4c41c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few alternative ORMs like Mongoid use ActiveModel pretty heavily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brainopia I don't understand your comment, ActiveModel isn't going to anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I've misread commit title, my bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=,(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're a smart cookie @jonleighton.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nooooooo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve been using the techniques below in yehuda's article successfully.
http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/
What impact does this have with “extend ActiveModel::……… “
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bwalsh No impact actually, this is removing the ability of including ActiveRecord::Model instead of inheriting from ActiveRecord::Base. Nothing in changing from ActiveModel and what Yehuda describes on his post :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually thinking of doing something like this by creating a 'BasicRecord' that is a subclass of ActiveRecord::Base that contains all the current AR logic except for the ORM/persistence parts. i.e. separate out the Rails data model from the database mapping in a pretty seamless way. Does that now seem like a bad code experiment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bf4 sounds interesting, PDI (Please Do Investigate) and try creating it as plugin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bf4 @guilleiguaran this sounds to me like Active Model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca lol, you're right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I missed it, but ActiveModel is an api that can be put together, but there's no actual 'This ActiveRecord::BasicRecord is ActiveRecord::Base without an persistence concerns. Where ActiveRecord::Base is maybe just ActiveRecord::BasicRecord with the mixin ActiveRecord::ORM' i.e there's no one module to include or class to subclass that implements all AR::Base stuff except persistence
BTW, @guilleiguaran when you said as a plugin, did you mean an engine outside of the Rails project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Active Model is also an API, but it is a set of modules that add behavior to Active Record.
Things like Validation, Callbacks, etc are defined at Active Model.
So whatever what this Basic Record should include it should be in Active Model, so every ORM can use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I didn't realize there's now an ActiveModel::Model in master/Rails 4 which does what I had in mind for use cases. It's pretty exciting it's already there :) Glad I read that code before I got too far along.
That said, I wonder if there's any reason the same code would workn't in Rails 3.x. It would be convenient not to need the boilerplate.

I was just browsing through this code and noticed ConnectionHandling is extended twice. Not sure if that's intentional, but it seemed weird and I thought I'd say something.