The Depot Application

The Depot Application

18 Active Record: The Basics 17 Migration

18 Active Record: The Basics

echo "Order.column_names" | IRBRC=tmp/irbrc rails console
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
Loading development environment (Rails 3.0.0.beta1)
>> Order.column_names
=> ["id", "name", "address", "email", "pay_type", "created_at", "updated_at", "customer_email", "placed_at", "attn", "order_type", "ship_class", "amount", "state"]
>> 
echo "Order.columns_hash[\"pay_type\"]" | IRBRC=tmp/irbrc rails console
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
Loading development environment (Rails 3.0.0.beta1)
>> Order.columns_hash["pay_type"]
=> #<ActiveRecord::ConnectionAdapters::SQLiteColumn:0x0000000192bd08 @null=true, @sql_type="varchar(10)", @name="pay_type", @scale=nil, @precision=nil, @limit=10, @type=:string, @default=nil, @primary=false>
>> 
sqlite3> select * from orders limit 1
            id = 1
          name = Dave Thomas
       address = 123 Main St
         email = customer@example.com
      pay_type = check
    created_at = 2010-02-11 19:12:56.696060
    updated_at = 2010-02-11 19:12:56.696060
customer_email = 
     placed_at = 2010-02-11 19:15:58.184032
          attn = 
    order_type = 
    ship_class = priority
        amount = 
         state = 
echo "Product.find(:first).price_before_type_cast" | IRBRC=tmp/irbrc rails console
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
Loading development environment (Rails 3.0.0.beta1)
>> Product.find(:first).price_before_type_cast
=> "29.95"
>> 
echo "Product.find(:first).updated_at_before_type_cast" | IRBRC=tmp/irbrc rails console
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
Loading development environment (Rails 3.0.0.beta1)
>> Product.find(:first).updated_at_before_type_cast
=> "2010-02-11 19:11:58.571133"
>> 
irb e1/ar/new_examples.rb
>> $: << File.dirname(__FILE__)
=> ["/home/rubys/git/rails/", "/home/rubys/git/rails/activeresource/lib", "/home/rubys/git/rails/actionmailer/lib", "/home/rubys/git/rails/railties/lib", "/home/rubys/git/rails/actionpack/lib", "/home/rubys/git/rails/activerecord/lib", "/home/rubys/git/rails/activemodel/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mail-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/arel-0.2.1/lib", "/home/rubys/git/rails/activesupport/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/thor-0.13.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/erubis-2.6.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/ext", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-mount-0.4.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-1.1.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/memcache-client-1.7.8/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-test-0.5.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-format-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/i18n-0.3.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/tzinfo-0.3.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rake-0.8.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-hyphen-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mime-types-1.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/builder-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/abstract-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/git/gorp/lib", "/home/rubys/git/arel/lib", "/home/rubys/git/rack/lib", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/x86_64-linux", ".", "/home/rubys/git/awdwr/data/code/e1/ar"]
>> require "connect"
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
=> true
 
?> require "rubygems"
=> []
>> require "active_record"
=> []
 
>> class Order < ActiveRecord::Base
>> end
=> nil
 
?> an_order = Order.new
=> #<Order id: nil, name: nil, address: nil, email: nil, pay_type: nil, created_at: nil, updated_at: nil, customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
>> an_order.name     = "Dave Thomas"
=> "Dave Thomas"
>> an_order.email    = "dave@example.com"
=> "dave@example.com"
>> an_order.address  = "123 Main St"
=> "123 Main St"
>> an_order.pay_type = "check"
=> "check"
>> an_order.save
=> true
 
?> Order.new do |o|
?>   o.name     = "Dave Thomas"
>>   # . . .
?>   o.save
>> end
=> #<Order id: 4, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
 
?> an_order = Order.new(
?>   :name     => "Dave Thomas",
?>   :email    => "dave@example.com",
?>   :address  => "123 Main St",
?>   :pay_type => "check")
=> #<Order id: nil, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: nil, updated_at: nil, customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
>> an_order.save
=> true
 
?> an_order = Order.new
=> #<Order id: nil, name: nil, address: nil, email: nil, pay_type: nil, created_at: nil, updated_at: nil, customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
>> an_order.name = "Dave Thomas"
=> "Dave Thomas"
>> # ...
?> an_order.save
=> true
>> puts "The ID of this order is #{an_order.id}"
The ID of this order is 6
=> nil
 
?> an_order = Order.create(
?>   :name     => "Dave Thomas",
?>   :email    => "dave@example.com",
?>   :address  => "123 Main St",
?>   :pay_type => "check")
=> #<Order id: 7, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
 
?> orders = Order.create(
?>   [ { :name     => "Dave Thomas",
?>       :email    => "dave@example.com",
?>       :address  => "123 Main St",
?>       :pay_type => "check"
>>     },
?>     { :name     => "Andy Hunt",
?>       :email    => "andy@example.com",
?>       :address  => "456 Gentle Drive",
?>       :pay_type => "po"
>>     } ] )
=> [#<Order id: 8, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 9, name: "Andy Hunt", address: "456 Gentle Drive", email: "andy@example.com", pay_type: "po", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
>> >> => nil
irb e1/ar/find_examples.rb
>> $: << File.dirname(__FILE__)
=> ["/home/rubys/git/rails/", "/home/rubys/git/rails/activeresource/lib", "/home/rubys/git/rails/actionmailer/lib", "/home/rubys/git/rails/railties/lib", "/home/rubys/git/rails/actionpack/lib", "/home/rubys/git/rails/activerecord/lib", "/home/rubys/git/rails/activemodel/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mail-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/arel-0.2.1/lib", "/home/rubys/git/rails/activesupport/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/thor-0.13.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/erubis-2.6.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/ext", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-mount-0.4.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-1.1.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/memcache-client-1.7.8/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-test-0.5.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-format-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/i18n-0.3.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/tzinfo-0.3.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rake-0.8.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-hyphen-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mime-types-1.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/builder-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/abstract-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/git/gorp/lib", "/home/rubys/git/arel/lib", "/home/rubys/git/rack/lib", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/x86_64-linux", ".", "/home/rubys/git/awdwr/data/code/e1/ar"]
>> require "connect"
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
=> true
>> require "logger"
=> []
 
>> ActiveRecord::Base.logger = Logger.new(STDERR)
=> #<Logger:0x00000003175e10 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x00000003175dd8 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00000003175b38 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x00000003175b00 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x000000031759e8>>>>
 
?> require "rubygems"
=> []
>> require "active_record"
=> []
>> require "pp"
=> ["PP"]
 
>> @params = {}
=> {}
>> def params
>>   @params
>> end
=> nil
 
?> class Order < ActiveRecord::Base
>>   named_scope :check, :conditions => {:pay_type => 'check'}
>>   named_scope :cc,    :conditions => {:pay_type => 'cc'}
>>   named_scope :po,    :conditions => {:pay_type => 'po'}
>> end
=> #<Proc:0x00000002ba19f0@/home/rubys/git/rails/activerecord/lib/active_record/named_scope.rb:116 (lambda)>
 
?> class Order < ActiveRecord::Base
>>   named_scope :recent, :conditions => ['created_at > ?', 1.week.ago]
>>   named_scope :since, lambda { |range| 
?>     { :conditions => ['created_at > ?', range] }
>>   }
>> end
=> #<Proc:0x00000002e3acc8@/home/rubys/git/rails/activerecord/lib/active_record/named_scope.rb:116 (lambda)>
 
>> class LineItem < ActiveRecord::Base
>> end
=> nil
 
>> class Product < ActiveRecord::Base
>> end
=> nil
 
?> # return an arbitrary order
?> order = Order.find(:first)
  *[1m*[36mOrder Load (1.0ms)  *[1mSELECT "orders".* FROM "orders" LIMIT 1
  *[1m*[35mOrder Load (0.4ms)  SELECT "orders".* FROM "orders" WHERE (name = 'Dave Thomas') LIMIT 1
=> #<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
 
>> # return an order for Dave
?> order = Order.find(:first, :conditions => "name = 'Dave Thomas'")
=> #<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
 
>> # return the latest order for Dave
?> order = Order.find(:first,
?>                    :conditions => "name = 'Dave Thomas'", 
?>                    :order      => "id DESC")
  *[1m*[36mOrder Load (0.3ms)  *[1mSELECT "orders".* FROM "orders" WHERE (name = 'Dave Thomas') ORDER BY id DESC LIMIT 1
  *[1m*[35mLineItem Load (0.3ms)  select line_items.* from line_items, orders where order_id = orders.id and orders.name = 'Dave Thomas' 
  *[1m*[36mOrder Load (0.4ms)  *[1mselect name, pay_type from orders
  *[1m*[35mOrder Load (0.7ms)  SELECT "orders".* FROM "orders"
=> #<Order id: 8, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
 
?> orders = LineItem.find_by_sql("select line_items.* from line_items, orders " +
?>                               " where order_id = orders.id                 " +
?>                               "   and orders.name = 'Dave Thomas'          ")
=> [#<LineItem id: 1, product_id: 3, order_id: 1, quantity: 1, total_price: 2850, created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", unit_price: #<BigDecimal:316ef98,'0.285E2',18(18)>>]
 
 
?> orders = Order.find_by_sql("select name, pay_type from orders")
=> [#<Order name: "Dave Thomas", pay_type: "check">, #<Order name: "Joe User", pay_type: "check">, #<Order name: "Dave Thomas", pay_type: "check">, #<Order name: "Dave Thomas", pay_type: nil>, #<Order name: "Dave Thomas", pay_type: "check">, #<Order name: "Dave Thomas", pay_type: nil>, #<Order name: "Dave Thomas", pay_type: "check">, #<Order name: "Dave Thomas", pay_type: "check">, #<Order name: "Andy Hunt", pay_type: "po">]
 
>> first = orders[0]
=> #<Order name: "Dave Thomas", pay_type: "check">
>> p first.attributes
{"name"=>"Dave Thomas", "pay_type"=>"check"}
=> {"name"=>"Dave Thomas", "pay_type"=>"check"}
>> p first.attribute_names
["name", "pay_type"]
=> ["name", "pay_type"]
>> p first.attribute_present?("address")
false
=> false
 
 
?> p Order.all
[#<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 2, name: "Joe User", address: "123 Main St., Anytown USA", email: "juser@hotmail.com", pay_type: "check", created_at: "2010-02-11 19:13:44", updated_at: "2010-02-11 19:13:44", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 3, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 4, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 5, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 6, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 7, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 8, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 9, name: "Andy Hunt", address: "456 Gentle Drive", email: "andy@example.com", pay_type: "po", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
=> [#<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 2, name: "Joe User", address: "123 Main St., Anytown USA", email: "juser@hotmail.com", pay_type: "check", created_at: "2010-02-11 19:13:44", updated_at: "2010-02-11 19:13:44", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 3, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 4, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 5, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 6, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 7, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 8, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 9, name: "Andy Hunt", address: "456 Gentle Drive", email: "andy@example.com", pay_type: "po", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
>> p Order.check(:order => "created_on desc").first
  *[1m*[36mOrder Load (0.4ms)  *[1mSELECT "orders".* FROM "orders" WHERE ("orders"."pay_type" = 'check') LIMIT 1
#<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
=> #<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
>> p Order.po.recent.count
  *[1m*[35mSQL (0.3ms)  SELECT COUNT(*) AS count_id FROM "orders" WHERE ("orders"."pay_type" = 'po') AND (created_at > '2010-02-04 19:18:20.694989')
  *[1m*[36mOrder Load (0.3ms)  *[1mSELECT "orders".* FROM "orders" WHERE ("orders"."pay_type" = 'check') AND ("orders"."name" = 'Dave Thomas') LIMIT 1
  *[1m*[35mOrder Load (0.3ms)  SELECT "orders".* FROM "orders" WHERE ("orders"."pay_type" = 'po') AND (created_at > '2010-02-04 19:18:20.694989')
  *[1m*[36mOrder Load (0.3ms)  *[1mSELECT "orders".* FROM "orders" WHERE ("orders"."pay_type" = 'po') AND (created_at > '2010-02-04 19:18:20.989647')
1
=> 1
>> p Order.check.find_by_name('Dave Thomas')
#<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
=> #<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
 
?> p Order.po.recent(:order => :created_at).to_a
[#<Order id: 9, name: "Andy Hunt", address: "456 Gentle Drive", email: "andy@example.com", pay_type: "po", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
=> [#<Order id: 9, name: "Andy Hunt", address: "456 Gentle Drive", email: "andy@example.com", pay_type: "po", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
>> p Order.po.since(1.week.ago).to_a
[#<Order id: 9, name: "Andy Hunt", address: "456 Gentle Drive", email: "andy@example.com", pay_type: "po", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
=> [#<Order id: 9, name: "Andy Hunt", address: "456 Gentle Drive", email: "andy@example.com", pay_type: "po", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
 
>> LineItem.delete_all
  *[1m*[35mSQL (65.9ms)  DELETE FROM "line_items" WHERE 1=1
=> 2
>> Product.delete_all
  *[1m*[36mSQL (57.6ms)  *[1mDELETE FROM "products" WHERE 1=1
=> 3
>> p = Product.create(:title => "Programming Ruby", :price => 49.95)
  *[1m*[35mSQL (0.3ms)  INSERT INTO "products" ("created_at", "description", "image_url", "price", "title", "updated_at") VALUES ('2010-02-11 19:18:21.130546', NULL, NULL, 49.95, 'Programming Ruby', '2010-02-11 19:18:21.130546')
=> #<Product id: 5, title: "Programming Ruby", description: nil, image_url: nil, created_at: "2010-02-11 19:18:21", updated_at: "2010-02-11 19:18:21", price: #<BigDecimal:4198a88,'0.4995E2',18(18)>>
>> LineItem.create(:quantity => 2, :unit_price => 49.95, :total_price => 99.90,
?>   :product_id => p.id, :order_id => first)
  *[1m*[36mSQL (0.4ms)  *[1mINSERT INTO "line_items" ("created_at", "order_id", "product_id", "quantity", "total_price", "unit_price", "updated_at") VALUES ('2010-02-11 19:18:21.235590', 1, 5, 2, 99, 49.95, '2010-02-11 19:18:21.235590')
=> #<LineItem id: 3, product_id: 5, order_id: 1, quantity: 2, total_price: 99, created_at: "2010-02-11 19:18:21", updated_at: "2010-02-11 19:18:21", unit_price: #<BigDecimal:31a43d8,'0.4995E2',18(18)>>
 
?> items = LineItem.find_by_sql("select *,                                  " +
?>                              "       quantity*unit_price as total_price, " +
?>                              "       products.title as title             " +
?>                              "  from line_items, products                " +
?>                              " where line_items.product_id = products.id ")
  *[1m*[35mLineItem Load (0.4ms)  select *, quantity*unit_price as total_price, products.title as title from line_items, products where line_items.product_id = products.id 
=> [#<LineItem id: 5, product_id: 5, order_id: 1, quantity: 2, total_price: 99, created_at: "2010-02-11 19:18:21", updated_at: "2010-02-11 19:18:21", unit_price: #<BigDecimal:2fe2500,'0.4995E2',18(18)>>]
>> li = items[0]
=> #<LineItem id: 5, product_id: 5, order_id: 1, quantity: 2, total_price: 99, created_at: "2010-02-11 19:18:21", updated_at: "2010-02-11 19:18:21", unit_price: #<BigDecimal:2fdc220,'0.4995E2',18(18)>>
>> puts "#{li.title}: #{li.quantity}x#{li.unit_price} => #{li.total_price}"
Programming Ruby: 2x49.95 => 99
=> nil
 
?> c1 = Order.count
  *[1m*[36mSQL (0.2ms)  *[1mSELECT COUNT(*) AS count_id FROM "orders"
=> 9
>> c2 = Order.count(:conditions => ["name = ?", "Dave Thomas"])
  *[1m*[35mSQL (0.2ms)  SELECT COUNT(*) AS count_id FROM "orders" WHERE (name = 'Dave Thomas')
=> 7
>> c3 = LineItem.count_by_sql("select count(*)                        " +
?>                            "  from line_items, orders              " +
?>                            " where line_items.order_id = orders.id " +
?>                            "   and orders.name = 'Dave Thomas'     ")
  *[1m*[36mLineItem Count (0.2ms)  *[1mselect count(*) from line_items, orders where line_items.order_id = orders.id and orders.name = 'Dave Thomas' 
=> 1
>> puts "Dave has #{c3} line items in #{c2} orders (#{c1} orders in all)"
Dave has 1 line items in 7 orders (9 orders in all)
=> nil
 
?> order  = Order.find_by_name("Dave Thomas")
  *[1m*[35mOrder Load (0.3ms)  SELECT "orders".* FROM "orders" WHERE ("orders"."name" = 'Dave Thomas') LIMIT 1
=> #<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>
>> orders = Order.find_all_by_name("Dave Thomas")
  *[1m*[36mOrder Load (0.7ms)  *[1mSELECT "orders".* FROM "orders" WHERE ("orders"."name" = 'Dave Thomas')
=> [#<Order id: 1, name: "Dave Thomas", address: "123 Main St", email: "customer@example.com", pay_type: "check", created_at: "2010-02-11 19:12:56", updated_at: "2010-02-11 19:12:56", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 3, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 4, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 5, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 6, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 7, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 8, name: "Dave Thomas", address: "123 Main St", email: "dave@example.com", pay_type: "check", created_at: "2010-02-11 19:18:17", updated_at: "2010-02-11 19:18:17", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
>> orders = Order.find_all_by_email(params['email'])
=> [#<Order id: 4, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>, #<Order id: 6, name: "Dave Thomas", address: nil, email: nil, pay_type: nil, created_at: "2010-02-11 19:18:16", updated_at: "2010-02-11 19:18:16", customer_email: nil, placed_at: "2010-02-11 19:15:58", attn: nil, order_type: nil, ship_class: "priority", amount: nil, state: nil>]
 
>> o = LineItem.find(:all,
?>                   :conditions => "pr.title = 'Programming Ruby'",
?>                   :joins => "inner join products as pr on line_items.product_id = pr.id")
  *[1m*[35mOrder Load (0.4ms)  SELECT "orders".* FROM "orders" WHERE ("orders"."email" IS NULL)
  *[1m*[36mLineItem Load (0.3ms)  *[1mSELECT "line_items".* FROM "line_items" inner join products as pr on line_items.product_id = pr.id WHERE (pr.title = 'Programming Ruby')
=> [#<LineItem id: 3, product_id: 5, order_id: 1, quantity: 2, total_price: 99, created_at: "2010-02-11 19:18:21", updated_at: "2010-02-11 19:18:21", unit_price: #<BigDecimal:23a8508,'0.4995E2',18(18)>>]
>> p o.size
1
=> 1
 
>> LineItem.delete_all
=> 1
 
>> res = Order.update_all("pay_type = 'wibble'")
  *[1m*[35mSQL (33.6ms)  DELETE FROM "line_items" WHERE 1=1
=> 9
>> p res
9
=> 9
 
>> res = Order.delete_all(["pay_type = ?", "wibble"])
  *[1m*[36mSQL (49.6ms)  *[1mUPDATE "orders" SET pay_type = 'wibble' 
=> 9
>> p res
9
=> 9
  *[1m*[35mSQL (49.4ms)  DELETE FROM "orders" WHERE (pay_type = 'wibble')
 
irb e1/ar/dump_serialize_table.rb
>> $: << File.dirname(__FILE__)
=> ["/home/rubys/git/rails/", "/home/rubys/git/rails/activeresource/lib", "/home/rubys/git/rails/actionmailer/lib", "/home/rubys/git/rails/railties/lib", "/home/rubys/git/rails/actionpack/lib", "/home/rubys/git/rails/activerecord/lib", "/home/rubys/git/rails/activemodel/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mail-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/arel-0.2.1/lib", "/home/rubys/git/rails/activesupport/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/thor-0.13.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/erubis-2.6.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/ext", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-mount-0.4.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-1.1.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/memcache-client-1.7.8/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-test-0.5.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-format-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/i18n-0.3.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/tzinfo-0.3.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rake-0.8.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-hyphen-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mime-types-1.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/builder-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/abstract-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/git/gorp/lib", "/home/rubys/git/arel/lib", "/home/rubys/git/rack/lib", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/x86_64-linux", ".", "/home/rubys/git/awdwr/data/code/e1/ar"]
>> require 'connect'
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
=> true
 
>> require 'rubygems'
=> []
>> require 'active_record'
=> []
>> require 'pp'
=> ["PP"]
 
>> ActiveRecord::Schema.define do
?>   create_table :purchases, :force => true do |t|
?>     t.string :name
>>     t.text   :last_five
>>   end
>> end
-- create_table(:purchases, {:force=>true})
   -> 0.1029s
=> nil
 
?> class Purchase < ActiveRecord::Base
>>   serialize :last_five
>>   # ...
?> end
=> Object
 
?> purchase = Purchase.new
=> #<Purchase id: nil, name: nil, last_five: nil>
>> purchase.name = "Dave Thomas"
=> "Dave Thomas"
>> purchase.last_five = [ 'shoes', 'shirt', 'socks', 'ski mask', 'shorts' ]
=> ["shoes", "shirt", "socks", "ski mask", "shorts"]
>> purchase.save
=> true
 
?> purchase = Purchase.find_by_name("Dave Thomas")
=> #<Purchase id: 1, name: "Dave Thomas", last_five: ["shoes", "shirt", "socks", "ski mask", "shorts"]>
>> pp purchase.last_five
["shoes", "shirt", "socks", "ski mask", "shorts"]
=> nil
>> pp purchase.last_five[3]
"ski mask"
=> nil
>> >> => nil
irb e1/ar/aggregation.rb
>> $: << File.dirname(__FILE__)
=> ["/home/rubys/git/rails/", "/home/rubys/git/rails/activeresource/lib", "/home/rubys/git/rails/actionmailer/lib", "/home/rubys/git/rails/railties/lib", "/home/rubys/git/rails/actionpack/lib", "/home/rubys/git/rails/activerecord/lib", "/home/rubys/git/rails/activemodel/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mail-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/arel-0.2.1/lib", "/home/rubys/git/rails/activesupport/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/thor-0.13.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/erubis-2.6.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/sqlite3-ruby-1.2.5/ext", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-mount-0.4.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-1.1.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/memcache-client-1.7.8/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rack-test-0.5.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-format-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/i18n-0.3.3/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/tzinfo-0.3.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/rake-0.8.7/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/text-hyphen-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/mime-types-1.16/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/builder-2.1.2/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/abstract-1.0.0/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/.rvm/gems/ruby-1.9.1-p376/gems/bundler-0.9.4/lib", "/home/rubys/git/gorp/lib", "/home/rubys/git/arel/lib", "/home/rubys/git/rack/lib", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby/1.9.1/x86_64-linux", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/vendor_ruby", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1", "/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/1.9.1/x86_64-linux", ".", "/home/rubys/git/awdwr/data/code/e1/ar"]
>> require "connect"
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
=> true
>> require "logger"
=> []
>> require "pp"
=> ["PP"]
 
>> #ActiveRecord::Base.logger = Logger.new(STDERR)
 
?> #require "rubygems"
?> #require_gem "active_record"
 
?> ActiveRecord::Schema.define do
?>   create_table :customers, :force => true do |t|
?>     t.datetime :created_at
>>     t.decimal  :credit_limit, :precision => 10, :scale => 2, :default => 100
>>     t.string   :first_name
>>     t.string   :initials
>>     t.string   :last_name
>>     t.datetime :last_purchase
>>     t.integer  :purchase_count, :default => 0
>>   end
>> end
-- create_table(:customers, {:force=>true})
   -> 0.0770s
=> nil
 
?> class LastFive
 
>>   attr_reader :list
 
>>   # Takes a string containing "a,b,c" and 
?>   # stores [ 'a', 'b', 'c' ]
?>   def initialize(list_as_string)
>>     @list = list_as_string.split(/,/)
>>   end
 
 
>>   # Returns our contents as a 
?>   # comma delimited string
?>   def last_five
>>     @list.join(',')
>>   end
>> end
=> nil
 
?> class Purchase < ActiveRecord::Base
>>   composed_of :last_five
>> end
=> #<ActiveRecord::Reflection::AggregateReflection:0x000000041d26c0 @macro=:composed_of, @name=:last_five, @options={}, @active_record=Purchase(id: integer, name: string, last_five: text)>
 
>> Purchase.delete_all
=> 1
 
?> Purchase.create(:last_five => LastFive.new("3,4,5"))
=> #<Purchase id: 2, name: nil, last_five: "3,4,5">
 
>> purchase = Purchase.find(:first)
=> #<Purchase id: 2, name: nil, last_five: "3,4,5">
 
>> puts purchase.last_five.list[1]     #=>  4
4
=> nil
 
 
?> class Name
>>   attr_reader :first, :initials, :last
 
>>   def initialize(first, initials, last)
>>     @first = first
>>     @initials = initials
>>     @last = last
>>   end
 
>>   def to_s
>>     [ @first, @initials, @last ].compact.join(" ")
>>   end
>> end
=> nil
 
?> class Customer < ActiveRecord::Base
 
>>   composed_of :name,
?>               :class_name => "Name",
?>               :mapping => 
?>                  [ # database       ruby
?>                    %w[ first_name   first ],
?>                    %w[ initials     initials ],
?>                    %w[ last_name    last ] 
>>                  ]
>> end
=> #<ActiveRecord::Reflection::AggregateReflection:0x000000032eea28 @macro=:composed_of, @name=:name, @options={:class_name=>"Name", :mapping=>[["first_name", "first"], ["initials", "initials"], ["last_name", "last"]]}, @active_record=Customer(id: integer, created_at: datetime, credit_limit: decimal, first_name: string, initials: string, last_name: string, last_purchase: datetime, purchase_count: integer)>
 
>> Customer.delete_all
=> 0
 
?> name = Name.new("Dwight", "D", "Eisenhower")
=> #<Name:0x00000003059618 @first="Dwight", @initials="D", @last="Eisenhower">
 
>> Customer.create(:credit_limit => 1000, :name => name)
=> #<Customer id: 1, created_at: "2010-02-11 19:18:28", credit_limit: #<BigDecimal:2c7d038,'0.1E4',9(18)>, first_name: "Dwight", initials: "D", last_name: "Eisenhower", last_purchase: nil, purchase_count: 0>
 
>> customer = Customer.find(:first)
=> #<Customer id: 1, created_at: "2010-02-11 19:18:28", credit_limit: #<BigDecimal:2c07998,'0.1E4',9(18)>, first_name: "Dwight", initials: "D", last_name: "Eisenhower", last_purchase: nil, purchase_count: 0>
>> puts customer.name.first    #=> Dwight
Dwight
=> nil
>> puts customer.name.last     #=> Eisenhower
Eisenhower
=> nil
>> puts customer.name.to_s     #=> Dwight D Eisenhower
Dwight D Eisenhower
=> nil
>> customer.name = Name.new("Harry", nil, "Truman")
=> #<Name:0x00000003f072d8 @first="Harry", @initials=nil, @last="Truman">
>> customer.save
=> true
 
>> >> => nil