On Mar 6, 1:47 pm, Scott LaBounty <[email protected]> wrote: > 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?
Sequel doesn't use proxies for associations. Use: usa.add_city(ny) See http://sequel.rubyforge.org/rdoc/classes/Sequel/Model/Associations.html for more details. Also, note that belongs_to will be deprecated in the next version. Use many_to_one. Jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
