ruby on rails - Generating seeds to tables not represented by a model -
If I have an intermediate table in my rail application that many authors and authors have many books, which are two objects (i.e., books and authors: representing associations between a book), I would refer this table to
seed .rb How can I populate the file? Update class author & lt; ActiveRecord :: Base has_and_belongs_to_many: Books # ... and Class Book & lt; ActiveRecord :: Base has_and_belongs_to_many: Authors # ... end
I think your If there is such a case between the two, between the two is is_ and_bollongs_to_me. you can do something like this: # seeds.rb Author = Author Creating (Name: 'Mark Twain') Writer Books & lt; & Lt; There is one more thing to check: Your model-less table is properly named: Authors / books ? Or try to write, which bang ! will cause more useful errors if it fails: # seeds.rb Author = Author.create! (Name: 'Mark Twain') Author.Books Make! (Title: 'Adventures of Tom Sawyer')
Comments
Post a Comment