I'm probably showing my ignorance of both Sequel and databases in general
here but in the following code:
-----------------------------------------------------------
require 'rubygems'
require 'sequel'
DB = Sequel.sqlite # Create an in-memory database
# Create a new Country table with columns of
# id, name, and population.
DB.create_table :countries do
primary_key :id
column :name, :text, :unique=>true
column :population, :integer
end
DB.create_table :cities do
primary_key :id
column :name, :text
foreign_key :country_id
end
class Country < Sequel::Model;
one_to_many :cities
end
class City < Sequel::Model
belongs_to :country
end
usa = Country.create(:name => 'U.S.A.', :population => 250000000)
ny = City.create(:name => 'New York')
# How to add ny to the USA?
usa.cities = ny
-----------------------------------------------------------
How do I add a city to the country that I created? Obviously the above
doesn't work. Do I have the tables set up correctly? Are the models correct?
--
Scott
http://steamcode.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---