Jeremy, Once again ... thanks for all the help. I really appreciate being able to get answers like this so quickly.
Scott On Sun, Oct 4, 2009 at 11:30 AM, Jeremy Evans <[email protected]>wrote: > > > > On Oct 4, 10:09 am, Scott LaBounty <[email protected]> wrote: > > I have the following: > > > > << > > require 'rubygems' > > require 'sequel' > > > > DB = Sequel.sqlite # Create an in-memory database > > > > DB.create_table(:users) do > > primary_key :id > > String :user_name > > foreign_key :question_id, :questions > > end > > > > DB.create_table(:questions) do > > primary_key :id > > String :question > > end > > > > class User < Sequel::Model > > many_to_one :question > > end > > > > class Question < Sequel::Model > > one_to_many :users > > end > > > > u = User.create(:user_name => 'slabounty') > > q = Question.create(:question => 'Where?') > > #u.add_question(q) > > q.add_user(u) > > > > puts "question = #{u.question.question}" > > > > > > > > Why is it that what I have works, but I can't do the opposite (i.e. the > > u.add_question(q) commented line)? > > You have many_to_one :question, so instead of an add_question/ > remove_question pair, you have question=. So would do: > > u.question = q > > You could actually do it all in one step: > > u = User.create(:user_name => 'slabounty', > :question=>Question.create(:question => 'Where?')) > > Jeremy > > > -- 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 -~----------~----~----~----~------~----~------~--~---
