相关疑难解决方法(0)

如何创建与ActiveResource对象的ActiveRecord关系?

假设我正在为已经拥有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表.这留下了几个问题:

  1. 我怎么告诉我的Person ActiveResource对象呢has_many Articles

  2. Articles.find(:first).author工作吗?会belongs_to甚至工作因为没有ActiveRecord,没有支撑台?

activerecord ruby-on-rails activeresource

5
推荐指数
2
解决办法
4147
查看次数