Last active
September 27, 2019 18:48
-
-
Save NILID/6ffc1687dda84cc4411830309cd39d36 to your computer and use it in GitHub Desktop.
User model with association by :parent_username
This file contains 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 User < ApplicationRecord | |
belongs_to :parent, primary_key: :username, | |
foreign_key: :parent_username, | |
class_name: 'User', | |
optional: true | |
has_many :children, primary_key: :username, | |
foreign_key: :parent_username, | |
class_name: 'User' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment