Skip to content

Instantly share code, notes, and snippets.

@dx7
Created July 23, 2010 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dx7/487603 to your computer and use it in GitHub Desktop.
Save dx7/487603 to your computer and use it in GitHub Desktop.
$ script/console
Loading development environment (Rails 2.3.8)
ruby-1.8.7-p299 > country = Country.create :name => "Brasil"
=> #<Country id: 3, name: "Brasil", created_at: "2010-07-23 15:37:58", updated_at: "2010-07-23 15:37:58">
ruby-1.8.7-p299 > state = State.create :name => "RJ"
=> #<State id: 2, name: "RJ", country_id: nil, created_at: "2010-07-23 15:38:15", updated_at: "2010-07-23 15:38:15">
ruby-1.8.7-p299 > country.states << state
=> [#<State id: 2, name: "RJ", country_id: 3, created_at: "2010-07-23 15:38:15", updated_at: "2010-07-23 15:38:28">]
ruby-1.8.7-p299 > city1 = City.create :name => "Rio de Janeiro"
=> #<City id: 3, name: "Rio de Janeiro", state_id: nil, created_at: "2010-07-23 15:39:00", updated_at: "2010-07-23 15:39:00">
ruby-1.8.7-p299 > city2 = City.create :name => "Niteroi"
=> #<City id: 4, name: "Niteroi", state_id: nil, created_at: "2010-07-23 15:39:16", updated_at: "2010-07-23 15:39:16">
ruby-1.8.7-p299 > state.cities << city1
=> [#<City id: 3, name: "Rio de Janeiro", state_id: 2, created_at: "2010-07-23 15:39:00", updated_at: "2010-07-23 15:39:28">]
ruby-1.8.7-p299 > state.cities << city2
=> [#<City id: 3, name: "Rio de Janeiro", state_id: 2, created_at: "2010-07-23 15:39:00", updated_at: "2010-07-23 15:39:28">, #<City id: 4, name: "Niteroi", state_id: 2, created_at: "2010-07-23 15:39:16", updated_at: "2010-07-23 15:39:30">]
ruby-1.8.7-p299 > state.cities
=> [#<City id: 3, name: "Rio de Janeiro", state_id: 2, created_at: "2010-07-23 15:39:00", updated_at: "2010-07-23 15:39:28">, #<City id: 4, name: "Niteroi", state_id: 2, created_at: "2010-07-23 15:39:16", updated_at: "2010-07-23 15:39:30">]
ruby-1.8.7-p299 > country.states
=> [#<State id: 2, name: "RJ", country_id: 3, created_at: "2010-07-23 15:38:15", updated_at: "2010-07-23 15:38:28">]
ruby-1.8.7-p299 > city1.state
=> #<State id: 2, name: "RJ", country_id: 3, created_at: "2010-07-23 15:38:15", updated_at: "2010-07-23 15:38:28">
ruby-1.8.7-p299 > state.country
=> #<Country id: 3, name: "Brasil", created_at: "2010-07-23 15:37:58", updated_at: "2010-07-23 15:37:58">
ruby-1.8.7-p299 > exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment