我有这个数据库架构
class User
has_many :accounts
end
class Account
belongs_to :user
belongs_to :biller
end
class Biller
has_many :accounts
end
如何获取用户的账单列表?
billers = user.?
我有这个数据库架构
class User
has_many :accounts
end
class Account
belongs_to :user
belongs_to :biller
end
class Biller
has_many :accounts
end
如何获取用户的账单列表?
billers = user.?
添加 has_many 关联与彻底选项:
class User
has_many :accounts
has_many :billers, through: :accounts
end
class Account
belongs_to :user
belongs_to :biller
end
class Biller
has_many :accounts
end
并像下面这样使用它:
billers = user.billers
更多信息请参阅 Active Record指南。