I am mapping 2 models:
User
Account
class Account
has_many :users
class User
has_one :account
The user table as the account_id in it.
Now on the Account model I want to create a 'primary user' which an account only has 1 off. The user table has a boolean flag :is_primary, how can I create a has_one on the account side for a user who has the is_primary and account_id mapped.
So the SQL would look like:
SELECT * FROM users where account_id=123 and is_primary = 1
So I want:
A user has an account. An account has many users, and has a single primary user also.