People 애플리케이션이 이미있는 게시 회사의 라이브러리 애플리케이션을 작성한다고 가정 해 보겠습니다.ActiveResource 개체에 대한 ActiveRecord 관계를 만들려면 어떻게해야합니까?
그래서 내 라이브러리 응용 프로그램에서 나는
class Person < ActiveResource::Base
self.site = "http://api.people.mypublisher.com/"
end
이 지금은 각 Person
에 대한 Article
의를 저장할 : 나는 내 데이터베이스에 다음 테이블이 거라고 상상
class Article < ActiveRecord::Base
belongs_to :person, :as => :author
end
를 :
Articles
id (PK) | title (string) | body (text) | author_id (integer)
author_id
은 정확히 Foreign-K 내가 피플 테이블을 가지고 있지 않기 때문에. 즉 몇 가지 질문을 잎 :
- 어떻게 내
Person
ActiveResource
객체를 알 수 있습니까 그것이has_many
Articles
? Articles.find(:first).author
이 작동합니까?belongs_to
도ActiveRecord
이없고 뒷받침 테이블이 없으므로 작동합니까?class Person < ActiveResource::Base self.site = "http://api.people.mypublisher.com/" def articles Article.find(:all, :conditions => { :person_id => self.id }) end def add_article(article) article.person_id = self.id end end
그러나 무엇
has_many
이벤트의 많은을 잃게 :