Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ActiveRecord

830 views

Published on

Introduction to ActiveRecord

Published in: Technology
  • Be the first to comment

  • Be the first to like this

ActiveRecord

  1. 1. ACTIVERECORD (AKA Why Rails doesn’t scale.)
  2. 2. CREATING NEW OBJECTS • Model#new • Model#create • model.association.build • :touch => (rails 2.3) http://ryandaigle.com/articles/2009/4/20/what-s-new-in-edge-rails-touching
  3. 3. CLASS METHODS • find • find_by* • find :include => :other_model (n+1) • find :join => :other_model
  4. 4. ASSOCIATIONS • has_one, has_many • has_and_belongs_to_many • belongs_to • :through =>
  5. 5. ASSOCIATION METHODS • scoping methods on associations
  6. 6. SCOPING • with_scope around_filter, scopes all finds to parent model • named_scopes • dynamic_scope (2.3) http://ryandaigle.com/articles/2008/12/29/what-s-new-in-edge-rails-dynamic-scope-methods
  7. 7. VALIDATIONS • built in validations • validate :some_method
  8. 8. CALLBACKS AND OBSERVERS • Transactional Semantics for free
  9. 9. LAW OF DEMETER • Structure vs Ecapsulation
  10. 10. PLUGINS • acts_as_list • acts_as_nested_set • acts_as_tree

×