Created
March 5, 2013 09:47
-
-
Save skorfmann/5089143 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 Invitation < ActiveRecord::Base | |
| belongs_to :invitable, primary_key: :email, foreign_key: :invitable_id, class_name: 'User' | |
| end | |
| class User < ActiveRecord::Base | |
| has_many :invitations, :primary_key, :email, foreign_key: :invitable_id | |
| end | |
| user = User.create(email: '[email protected]') | |
| invitation = Invitation.create(invitable: user) | |
| invitation.reload | |
| invitation.invitable_id == user.email # false | |
| invitation.invitable_id == user.id # true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it's the typos in your snippet:
:primary_key, :email...? This works for me:migration:
user.rb:
invitation.rb:
in the console: