내가이 User
2를 통해 테이블에 연결되는 모든 articles
얻을 필요가있는 상황에있어 : 레일스에서 여러 개의 테이블 중에서 선택하십시오 - [table_1, table_2]까지 많은 "articles"이 있습니까?
- article_access은 : 공공의 기사 사용자 : 기사에게
- article_favorites를보고 사용자에게 권한을 부여 이
을 즐겨 찾기 한 그래서 액티브 당신이있을 수 있습니다 :
class User < ActiveRecord::Base
has_many :article_access_tokens
has_many :article_favorites
def articles
unless @articles
ids = article_access_tokens.all(:select => "article_id").map(&:article_id) + article_favorites.all(:select => "article_id").map(&:article_id)
@articles = Article.send(:scoped, :conditions => {:id => ids.uniq})
end
@articles
end
end
그건 기본적으로 두 개의 별도 테이블에서 읽는 articles
연결을 제공합니다. 질문은 그래, 무엇 오른쪽 방법이 무엇입니까?
어떻게 든 SQL SELECT를 호출하여이 작업을 수행 할 수 있습니까?