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
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)
# 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.
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.
--
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
-~----------~----~----~----~------~----~------~--~---