2016-07-12 4 views
0

私はこれが問題である
レール:親の親の親から範囲

School 
    has_many :students 
    has_many :accounts, :through => :students 

    Student 
    belongs_to :school 
    has_one :account 

    Account 
    belongs_to :student 

以下の関係を持って、私は学校
のカップルを持っていると私はアカウントを取得したいがして、特定の学校に所属ページ区切り
これをロードするにはどうすればよいですか?

@accounts = Accounts.where(...).page(params[:page]).per(10) 


私は

School 
    has_many :classrooms 

    Classroom 
    belongs_to :school 
    has_many :students 
    has_many :accounts, :through => :students 

    Student 
    belongs_to :classroom 
    has_one :account 

    Account 
    belongs_to :student 

と質問以下の関係を持っている私の質問
を逃した私は、あなたができるようにすべきだと思う:)

+0

あなたの質問へのアップデートに合わせて私の回答を更新しました – oreoluwa

答えて

1

同じです行うこと:

更新問題、あなたはまだやると上記のクエリを使用して同じ結果を得ることができますに基づいて
school = School.first 
@accounts = school.accounts.page(params[:page]).per(10) 

UPDATE

School 
    has_many :classrooms 
    has_many :accounts, through: :classrooms 
+0

ありがとうoreoluwa! – PeaceB

0

あなたは

好きな学校idで学校を見つける必要があります
@school = School.find(params[:id]) 

この声明では、この特定の学校に関連付けられたアカウントを取得できます。

@accounts = @school.accounts.page(params[:page]).per(10) 
+0

おかげでVishal :) – PeaceB