【发布时间】:2013-11-23 04:03:04
【问题描述】:
我一直在努力解决 has_many :through 关系。假设我有以下表格:
Orgs
==============
id Integer
name String
Accounts
==============
id Integer
name String
type Integer
org_id Integer
Users
====================
id Integer
account_id Integer
name String
然后我将模型设置如下:
class Orgs < ActiveRecord::Base
has_many :accounts
has_many :users, through :accounts
class Accounts < ActiveRecord::Base
has_many :users
belongs_to :orgs
class Users < ActiveRecord::Base
belongs_to :accounts
如何获取帐户 type=3 的 Orgs 用户(例如)?我在哪里放置条件?
【问题讨论】:
标签: ruby-on-rails activerecord has-many