SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
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/

Contenu connexe

Similaire à Active record makeover

Productionizing a Machine Learning System at a Large Australian Telco with Ca...
Productionizing a Machine Learning System at a Large Australian Telco with Ca...Productionizing a Machine Learning System at a Large Australian Telco with Ca...
Productionizing a Machine Learning System at a Large Australian Telco with Ca...
Databricks
 
Maximising Your SERP Potential - Enhance your listings with Rich Snippets
Maximising Your SERP Potential - Enhance your listings with Rich Snippets Maximising Your SERP Potential - Enhance your listings with Rich Snippets
Maximising Your SERP Potential - Enhance your listings with Rich Snippets
Peter Handley
 

Similaire à Active record makeover (20)

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

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Active record makeover