我有三種模式:帳戶,成員和子級。Rails。虛擬屬性(來自父級模型)查詢
Member belongs to Account
Child belongs to Member
部件具有ACCOUNT_ID屬性 兒童沒有一個ACCOUNT_ID屬性
因此,我可以做到這一點...
Member.where(:account_id => current_user.account.id)
c = Child.last
c.member.account_id
在索引操作,我想列出所有屬於特定帳戶的孩子。我不想在children
表中添加額外的account_id
列。
當然,我不能做到這一點...
Child Model
def account_id
self.member.account_id
end
Children Controller
Child.where(:account_id => current_user.account.id)
有沒有辦法列出屬於特定帳戶的所有兒童,而無需添加account_id
屬性?
順便說一句,我有這對現有的查詢......
@children = Child.search(params[:search]).order(sort_column + ' ' + sort_direction).page(params[:page]).per(10)