SlideShare a Scribd company logo
Active Record Makeover
         Marty Haught
             @mghaught
       http://martyhaught.com
Boulder Ruby




Longmont, Colorado
ActiveRecord feels like
Growing tired of this
Wished I was driving...
...but I can’t


• Existing system
• Project already committed
or doesn’t make sense

• Not the best fit for project
• No significant gain
• rdbms solves the problem
So where’s the love?

• Where’s the new hotness
• Envious of the nosql gems
• Want a better way to model data
Rails 3’s ActiveRecord




   Unpimp your auto
Engine’s been rebuilt


• ActiveRelation
• arel gem - relational algebra
• Consistency under the hood
Easier to model with


• Simpler api
• Fully chainable
• Lazy loaded
find all


Rails 2x
Rails 3
first, last, count


Rails 2x
Rails 3
Finder methods
Chainable

Rails 2x
Rails 3
What about scopes?


Rails 2x
Rails 3
Reusing scopes
Merging scopes
Using scoped
Mix and match
Behaves like the model
new
create        delete
create!       delete_all
find           update
destroy       update_all
destroy_all   exists?
Building with where values
Lazy loaded
• won’t interact with the db until accessed
• such as each, map, etc.
• force load - all, first, last
Plays nice with caching
Modeling with class
to_sql
where_values
Extend the possibilities

• ActiveRecord::QueryMethods opens a door
• invokes to_sql on where_values unless a String
• pass in your own objects that create sql
MetaSearch & MetaWhere
            Ernie Miller




   http://github.com/ernie/meta_where
   http://github.com/ernie/meta_search
Got some hotness

• new engine
• concise and readable
• simpler to model
• flexible
• extendable
Go have fun, get dirty
Thank you
                              Marty Haught
                                 @mghaught
                            mghaught@gmail.com
                           http://martyhaught.com



Image Credits
      wagon - http://www.flickr.com/photos/halfy/3410561333
      vw car - http://www.youtube.com/watch?v=qgEvy60bZYI
      white race car - http://www.flickr.com/photos/33031095@N03/4538638400/
      yellow sports car - http://www.flickr.com/photos/retinafunk/57699167/
      red sports car - http://www.flickr.com/photos/freefoto/3844246045/
      gray sports car - http://www.flickr.com/photos/doramosnoopy/2479741916/
      blue sports car - http://www.flickr.com/photos/chorwedel/4398697300/
      racing cars - http://www.flickr.com/photos/oizumi/2582189751/

More Related Content

PPS
I can has API? A Love Story
PPTX
Bring GraphQL to your ember project
PDF
select-fix(일괄 바꿈) 프로젝트 소개
PDF
Introduction to Social APIs
PDF
Getting Started With Sass | WC Philly 2015
PDF
Open Source Principles for Internal Engineering Teams
PDF
Angular.JS: Do it right
KEY
Dev's Guide to Feedback Driven Development
I can has API? A Love Story
Bring GraphQL to your ember project
select-fix(일괄 바꿈) 프로젝트 소개
Introduction to Social APIs
Getting Started With Sass | WC Philly 2015
Open Source Principles for Internal Engineering Teams
Angular.JS: Do it right
Dev's Guide to Feedback Driven Development

Similar to Active record makeover (20)

KEY
Ruby APIs for NoSQL - Polyglot Persistence - GoGaRuCo 2010
KEY
Contributing to rails
PPTX
Building Rackspace Cloud Monitoring
PDF
Agile analytics applications on hadoop
PPTX
Austin cassandra meetup
PPTX
How does Java 8 exert hidden power on Test Automation?
PPTX
Untangling spring week9
PDF
Non-Framework MVC sites with PHP
PDF
Validating Big Data Pipelines - Big Data Spain 2018
KEY
Windycityrails page performance
PDF
Improving Apache Spark for Dynamic Allocation and Spot Instances
PDF
What is quality code? From cruft to craft
PDF
End-to-End Data Pipelines with Apache Spark
PDF
Productionizing a Machine Learning System at a Large Australian Telco with Ca...
PPTX
ADT02 - Java 8 Lambdas and the Streaming API
PDF
Ab(Using) the MetaCPAN API for Fun and Profit v2013
PDF
Maximising Your SERP Potential - Enhance your listings with Rich Snippets
PPTX
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
PDF
20180328 av kaggle_jigsaw_with_amlwb
PDF
Mike fowler - Getting started with machine learning (london 2019)
Ruby APIs for NoSQL - Polyglot Persistence - GoGaRuCo 2010
Contributing to rails
Building Rackspace Cloud Monitoring
Agile analytics applications on hadoop
Austin cassandra meetup
How does Java 8 exert hidden power on Test Automation?
Untangling spring week9
Non-Framework MVC sites with PHP
Validating Big Data Pipelines - Big Data Spain 2018
Windycityrails page performance
Improving Apache Spark for Dynamic Allocation and Spot Instances
What is quality code? From cruft to craft
End-to-End Data Pipelines with Apache Spark
Productionizing a Machine Learning System at a Large Australian Telco with Ca...
ADT02 - Java 8 Lambdas and the Streaming API
Ab(Using) the MetaCPAN API for Fun and Profit v2013
Maximising Your SERP Potential - Enhance your listings with Rich Snippets
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
20180328 av kaggle_jigsaw_with_amlwb
Mike fowler - Getting started with machine learning (london 2019)
Ad

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
KodekX | Application Modernization Development
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation theory and applications.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
KodekX | Application Modernization Development
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Ad

Active record makeover