Created
March 20, 2010 02:25
-
-
Save dewski/338409 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MongoMapper::Document | |
| key :name, String | |
| # etc | |
| many :addresses | |
| end | |
| class Address | |
| # Used for things that don't need associations | |
| include MongoMapper::EmbeddedDocument | |
| key :street, String | |
| key :zip, Integer, :length => 5 | |
| # etc | |
| # I think there is an enum kind of thing for this | |
| key :state, String | |
| end |
This file contains hidden or 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
This file contains hidden or 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 Item | |
| include MongoMapper::Document | |
| key :name, String | |
| key :user_id, ObjectId | |
| key :likes_ids, Array | |
| key :_type, Object | |
| many :likes | |
| end | |
| class Picture < Item | |
| key :url, String | |
| key :rating, Integer | |
| end | |
| class Video < Item | |
| key :url, String, :required => true | |
| key :length, Integer, :default => 0 | |
| end | |
| p = Picture.new({ ... }).save | |
| v = Video.new({ ... }).save | |
| => Item.all | |
| # [Picture, Video] | |
| => Video.all | |
| # [Video] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment