Jeremy, Thanks for the explanation, but I'm still seeing a problem with these four lines (which should work if I'm reading your explanation correctly).
cProgrammingLanguageAuthors = cProgrammingLanguage.authors_dataset dennisRitchieBooks = ritchie.books_dataset authors = cProgrammingLanguage.authors books = ritchie.books In each case I get an error that a method doesn't exist (authors_dataset, books_dataset, authors, and books respectively). Thanks again, Scott On Mon, Mar 9, 2009 at 11:33 AM, Jeremy Evans <[email protected]>wrote: > > On Mar 9, 9:09 am, Scott LaBounty <[email protected]> wrote: > > Once again ignorance of both databases in general and Sequel > specifically. > > If I have the following code: > > > > ------------------------------------ > > require 'rubygems' > > require 'sequel' > > > > DB = Sequel.sqlite # Create an in-memory database > > > > DB.create_table :books do > > primary_key :id > > column :title, :text, :unique=>true > > column :population, :integer > > end > > > > DB.create_table :authors do > > primary_key :id > > column :name, :name > > end > > > > DB.create_table :authors_books do > > primary_key :id > > foreign_key :book_id > > foreign_key :author_id > > end > > > > class Book < Sequel::Model > > many_to_many :author > > end > > > > class Author < Sequel::Model > > many_to_many :book > > end > > > > # Is this needed? > > class Author_Book < Sequel::Model; end > > No, that's not needed, though it doesn't harm anything. > > > cProgrammingLanguage = Book.create(:title => 'The C Programming > Language') > > kernighan = Author.create(:name => 'Brian Kernighan') > > ritchie = Author.create(:name => 'Dennis Ritchie') > > cProgrammingLanguage.add_author(kernighan) > > cProgrammingLanguage.add_author(ritchie) > > kernighan.add_book(cProgrammingLanguage) > > ritchie.add_book(cProgrammingLanguage) > > You don't need to add it both ways. If you do > > cProgrammingLanguage.add_author(kernighan) > > then: > > kernighan.books.include(cProgrammingLanguage).should == true > > > # cProgrammingLanguageAuthors = cProgrammingLanguage.authors_dataset > > # dennisRitchieBooks = ritchie.books_dataset > > > > ------------------------------------ > > > > Do I need the Author_Book model? Did I name if right if I did? How do I > get > > all of the authors for a book? How do I get all of the books an author > > wrote. > > book.authors is an array of Author instances > author.books is an array of Book instances > book.authors_dataset is the dataset representing the author's books > author.books_dataset is the dataset representing the book's authors > > > Once again, I've really appreciated all the help I've received on this > list. > > I'll probably be documenting what I find (OK, what you tell me) on my > blog, > > so that hopefully others will be able to find this information as they're > > just starting out. > > You're welcome. Blog posts explaining Sequel's features are much > appreciated. > > Thanks, > 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 -~----------~----~----~----~------~----~------~--~---
