Thanks Jeremy. That's what I was looking for.

Scott

On Wed, Aug 18, 2010 at 7:09 AM, Jeremy Evans <[email protected]>wrote:

> On Aug 18, 6:09 am, Scott LaBounty <[email protected]> wrote:
> > All
> >
> > I have the following migration ...
> >
> > <<
> > # Sequel migration that creates the books, authors, and authors_books.
> > Class.new(Sequel::Migration) do
> >     def up
> >         create_table(:books) do
> >             primary_key :id
> >             String :title
> >         end
> >
> >         create_table(:authors) do
> >             primary_key :id
> >             String :first_name
> >             String :last_name
> >         end
> >
> >         create_table(:authors_books) do
>
> >             foreign_key :author_id, :authors
> >             foreign_key :book_id, :books
> >         end
> >
> >         # Create a library administrator.
>          book_id = from(:books).insert(:title => 'Programming Ruby')
>          author_id = from(:authors).insert(:first_name =>
> 'Dave', :last_name => 'Thomas')
>         from(:authors_books).insert(:book_id => book_id, :author_id
> => author_id)
> >
> >     end
> >
> >     def down
> >         drop_table(:books, :authors, :authors_books)
> >     end
> > end
> >
> >
> >
> > and I want to hook the book (Programming Ruby) with the author (Dave
> Thomas)
> > in the authors_books table. The documentation says not to use models
> (pretty
> > emphatically) which would be how I'd normally do this. Actually, I
> wouldn't
> > normally do this at all, this is just to save myself a bunch of
> irrelevant
> > coding elsewhere.
> >
> > Thoughts?
>
> You don't need a primary key in the join table, and since you just
> care about the returned primary key, you save the values for the
> inserts into the main model table, and do your own insert into the
> join table.
>
> 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]<sequel-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/sequel-talk?hl=en.
>
>


-- 
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.

Reply via email to