Created
October 23, 2008 01:05
-
-
Save notch8-old/18882 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
| require 'couchrest' | |
| CouchRest::Model.default_database = CouchRest.database!("http://localhost:5984/test") | |
| class CategoryList < CouchRest::Model | |
| key_accessor :categories | |
| cast :categories, :as => ["Category"] | |
| end | |
| class Category < CouchRest::Model | |
| key_accessor :name | |
| key_accessor :categories | |
| # cast :categories, :as => ["Category"] | |
| view_by :name, | |
| :map => | |
| "function(doc) { | |
| if (doc['couchrest-type'] == 'CategoryList' && doc.categories) { | |
| doc.categories.forEach(function(category){ | |
| emit(category.name, category); | |
| }); | |
| } | |
| }" | |
| end | |
| @category = Category.new(:name => "Biology") | |
| @sub_category = Category.new(:name => "Sub Biology") | |
| @category_list = CategoryList.new(:categories => [@category]) | |
| @category_list.save | |
| categories = Category.by_name(:key => "Biology") | |
| puts categories.inspect | |
| puts | |
| puts "#{categories.first.class.inspect} <- Should be Category" | |
| puts | |
| puts "#{categories.first.name.inspect} <- Should be the string 'Biology'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment