0

我刚开始使用rails,

我有一个使用一组 3 个属性生成的模型,并且我为它编写了控制器和视图,现在我需要另一个数据库或具有 4 个属性的模型,其中必须链接新模型的第二个和第三个属性对于原始数据库中的 2 个属性,如何创建或生成此模型?

主数据库(书籍)

BookID, Bookname , no.of.books

辅助数据库(使用)Customername、Bookname、noofbooks_rented。

更改必须反映在原始数据库上。我在这里先向您的帮助表示感谢..

4

1 回答 1

0

在您的图书模型中

class BooK < ActiveRecord::Base
belongs_to :customer

def count_books
  //count all books on a particular user
end

end

在您的客户模型中

class Customer <ActiveRecord::Base
has_many :books
end
于 2012-04-29T23:10:45.887 回答