Skip to content

Instantly share code, notes, and snippets.

@zenom
Created June 8, 2010 00:50
Show Gist options
  • Save zenom/429447 to your computer and use it in GitHub Desktop.
Save zenom/429447 to your computer and use it in GitHub Desktop.
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
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