Created
February 1, 2012 09:24
-
-
Save JeanMertz/1716117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Account < ActiveRecord::Base | |
| has_many :memberships | |
| has_many :users, through: :memberships | |
| has_many :team_members, through: :memberships, source: :user, conditions: { 'memberships.role' => 'TeamMember' } | |
| has_one :ownership, class_name: 'Membership', conditions: { 'memberships.role' => "Owner" } | |
| has_one :owner, through: :ownership, source: :user | |
| end | |
| # Account.new.users.build | |
| 1.9.3 (main):0 > Account.new.users.build | |
| +----+------+------+ | |
| | id | name | emai | | |
| +----+------+------+ | |
| | | | | | |
| +----+------+------+ | |
| 1 row in set | |
| # Account.new.team_members.build | |
| 1.9.3 (main):0 > Account.new.team_members.build | |
| +----+------+------+ | |
| | id | name | emai | | |
| +----+------+------+ | |
| | | | | | |
| +----+------+------+ | |
| 1 row in set | |
| # Account.new.build_owner? owners.build? ...? | |
| 1.9.3 (main):0 > Account.new.build_owner | |
| NoMethodError: undefined method `build_owner' for #<Account id: nil, name: nil, created_at: nil, updated_at: nil> | |
| 1.9.3 (main):0 > Account.new.owner.build | |
| NoMethodError: undefined method `build' for nil:NilClass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment