我正在映射2个模型:
User
Account
class Account
has_many :users
class User
has_one :account
Run Code Online (Sandbox Code Playgroud)
用户表作为其中的account_id.
现在在帐户模型上我想创建一个帐户只有1个关闭的"主要用户".用户表有一个布尔标志:is_primary,如何在帐户端为具有is_primary和account_id映射的用户创建has_one.
所以SQL看起来像:
SELECT * FROM users where account_id=123 and is_primary = 1
Run Code Online (Sandbox Code Playgroud)
所以我想:
用户拥有一个帐户.帐户有很多用户,并且还有一个主要用户.