Skip to content

Instantly share code, notes, and snippets.

@NILID
Last active September 27, 2019 18:48
Show Gist options
  • Save NILID/6ffc1687dda84cc4411830309cd39d36 to your computer and use it in GitHub Desktop.
Save NILID/6ffc1687dda84cc4411830309cd39d36 to your computer and use it in GitHub Desktop.
User model with association by :parent_username
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