-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23ce2f6
commit 77b18d7
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77b18d7
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.
@tenderlove – I read through your (amazing) AdequateRecord contributions to ActiveRecord, and it got me thinking:
What if we could decouple these optimizations and its
Relation
class and expose them as part ofActiveModel
?Let me explain this statement and take you on the 🎢 that's in my mind.
As you illustrated in your post, ActiveRecord constructs SQL queries after doing a few transformations:
Relation
->ARel::Node
->SQLString
.What if there was no database at all? Can you think of any other piece of code where it would be useful to:
Person.find_by(name: 'Aaron')
orPerson.find(3)
, andWell, I think that a perfect example is ActiveResource! ActiveResource inherits from ActiveModel, but then has to newly define methods like
find
to feel like ActiveRecord.Instead, if
ActiveModel
itself exposed theRelation
class with its modules (FinderMethods
,QueryMethods
, …), then both ActiveRecord and ActiveResource would benefit from the caching optimization and share the same public interface.The implementation, of course, would be different (in ActiveRecord
User.find(1)
would meanSELECT * FROM users WHERE id=1
, in ActiveResource it would meanGET /users/1
), but having a common public interface would… be great!I know this a is a very long shot… and I might be completely missing something, I just thought I'd share and wait for your feedback! Thanks for you amazing work 🍭
77b18d7
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.
77b18d7
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.
Sounds good!