假设我正在为已经拥有 People 应用程序的出版公司编写图书馆应用程序。
所以在我的图书馆应用程序中,我有
class Person < ActiveResource::Base
self.site = "http://api.people.mypublisher.com/"
end
现在我想Article
为每个存储 s Person
:
class Article < ActiveRecord::Base
belongs_to :person, :as => :author
end
我想我的数据库中有下表:
Articles
id (PK) | title (string) | body (text) | author_id (integer)
author_id
不完全是外键,因为我没有 People 表。这留下了几个问题:
我如何告诉我的
Person
ActiveResource
对象呢has_many
Articles
?会
Articles.find(:first).author
工作吗?belongs_to
考虑到没有ActiveRecord
也没有后备表,甚至会起作用吗?