What about: Author.create(:name => "Lewis Carroll", :books => [ Book.new(:name => "Alice in Wonderland") ]) ?
On 1/12/07, Kevin Burk <[EMAIL PROTECTED]> wrote:
How does one populate a join table using a data migration? Here's the situation. I have a HABM relationship between authors and books; both tables are created and populated. I've created the join table, authors_books, to contain author_id and book_id. I want to use a data migration to populate the table-what's the code for this? Since there isn't a model for the join table, it's not an object... If I want to add data in a migration to the books table, I can simply use: Book.create(:name => "Alice in Wonderland") Likewise, the author table can migrate with data like so: Author.create(:name => "Lewis Carroll"). If the book_id is 1, and the author_id is 1, how do I get this information in the join table? Since it's not an object in and of itself, what's the code to create and populate new rows in this table? I know I can hack around it by creating a model for the join and using the :through => New_Model to make the connection, but it seems that there must be an easier way to get the basic data in the join table and still have the version control over the data through the data migration. -- *************************************** BURK DESIGN GROUP http://www.BurkDesignGroup.com mailto:[EMAIL PROTECTED] 6161 El Cajon Blvd #306 San Diego, CA 92115 PHONE (619) 583-2311 FAX (619) 583-5801 *************************************** _______________________________________________ Sdruby mailing list [email protected] http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________ Sdruby mailing list [email protected] http://lists.sdruby.com/mailman/listinfo/sdruby
