Skip to content

Instantly share code, notes, and snippets.

@abhishek0
Created August 9, 2013 09:38
Show Gist options
  • Save abhishek0/6192432 to your computer and use it in GitHub Desktop.
Save abhishek0/6192432 to your computer and use it in GitHub Desktop.
Many to one on same mongoid collection
admin = User.create! :first_name => 'admin', :last_name => 'admin', :email => '[email protected]', :mobile => '9999911111', :locality => 'Goregaon', :city => 'Mumbai', :user_type => 'admin', :username => '[email protected]', :password => 'admin'
franchisee = User.create! :first_name => 'franchisee', :last_name => 'franchisee', :email => '[email protected]', :mobile => '9999911111', :locality => 'Goregaon', :city => 'Mumbai', :user_type => 'franchisee', :username => '[email protected]', :password => 'franchisee'
franchisee.parent = admin
franchisee.save!
class User
include Mongoid::Document
store_in collection: "users"
validates :first_name,:last_name,:email,:mobile, presence: true
validates :locality,:city, presence: true
belongs_to :parent, class_name: "User"
has_many :children, class_name: "User"
field :first_name, type: String
field :last_name, type: String
field :email, type: String
field :mobile, type: String
field :locality, type: String
field :city, type: String
field :address, type: String
field :blood_grp, type: String
field :emergency_no, type: String
field :user_type, type: String
field :dob, type: Integer
field :username, type: String
field :password, type: String
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment