欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

has_many 关联关系表单 提交

程序员文章站 2022-07-15 20:04:20
...
class Author
  has_many :books
end

class Book
  belongs_to :author
end


author = Author.create(:name => "zcy", :book_ids => [1,2,3])
author.books.collect(&:id)    =>    [1,2,3]