Created
August 9, 2013 09:38
-
-
Save abhishek0/6192432 to your computer and use it in GitHub Desktop.
Many to one on same mongoid collection
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
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! |
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 | |
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