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