SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
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/

Más contenido relacionado

Similar a 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
 

Similar a 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)
 

Último

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Active record makeover