Created
June 8, 2010 00:50
-
-
Save zenom/429447 to your computer and use it in GitHub Desktop.
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 Site | |
include Mongoid::Document | |
include Mongoid::Timestamps # adds created_at and updated_at fields | |
# field <name>, :type => <type>, :default => <value> | |
field :name, :type => String | |
field :url, :type => String | |
embedded_in :sponsor, :inverse_of => :sites | |
# You can define indexes on documents using the index macro: | |
# index :field <, :unique => true> | |
# You can create a composite key in mongoid to replace the default id using the key macro: | |
# key :field <, :another_field, :one_more ....> | |
key :url | |
validates_presence_of :name | |
validates_uniqueness_of :url | |
end |
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 Sponsor | |
include Mongoid::Document | |
include Mongoid::Timestamps # adds created_at and updated_at fields | |
# field <name>, :type => <type>, :default => <value> | |
field :name, :type => String | |
field :url, :type => String | |
# You can define indexes on documents using the index macro: | |
# index :field <, :unique => true> | |
#index :name <, :unique => true> | |
# You can create a composite key in mongoid to replace the default id using the key macro: | |
# key :field <, :another_field, :one_more ....> | |
index :name | |
index :url | |
embeds_many :sites | |
accepts_nested_attributes_for :sites, :reject_if => lambda {|attrs| attrs["name"].blank? } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment