Skip to content
This repository
Browse code

Setting default model type name to 'model'

  • Loading branch information...
commit bc4c8719d0dd8430b5817b135b048f20b8d84d02 1 parent 3764d1c
Sam Lown authored April 18, 2011
19  README.md
Source Rendered
@@ -11,6 +11,14 @@ it is not possible to load ActiveModel into programs that do not use ActiveSuppo
11 11
 
12 12
 CouchRest Model is only properly tested on CouchDB version 1.0 or newer.
13 13
 
  14
+*WARNING:* As of April 2011 and the release of version 1.1.0, the default model type key is 'model' instead of 'couchrest-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:
  15
+
  16
+    CouchRest::Model::Base.configure do |config|
  17
+      config.model_type_key = 'couchrest-type'
  18
+    end
  19
+
  20
+This is because CouchRest Model's are not couchrest specific and may be used in any other system such as a Javascript library, the model type should reflect this.
  21
+
14 22
 ## Install
15 23
 
16 24
 ### Gem
@@ -57,6 +65,7 @@ Try some of these gems that add extra funcionality to couchrest_model:
57 65
 * [couch_photo](http://github.com/moonmaster9000/couch_photo) - attach images to documents with variations (Matt Parker)
58 66
 * [copycouch](http://github.com/moonmaster9000/copycouch) - single document replication on documents (Matt Parker)
59 67
 * [recloner](https://github.com/moonmaster9000/recloner) - clone documents easily (Matt Parker)
  68
+* [couchrest_localised_properties](https://github.com/samlown/couchrest_localised_properties) - Transparent support for localised properties (Sam Lown)
60 69
 
61 70
 If you have an extension that you'd us to add to this list, please get in touch!
62 71
 			   
@@ -148,7 +157,7 @@ Boolean or TrueClass types will create a getter with question mark at the end:
148 157
 
149 158
     @cat.awake?   # true
150 159
 
151  
-Adding the +:default+ option will ensure the attribute always has a value.
  160
+Adding the `:default` option will ensure the attribute always has a value.
152 161
 
153 162
 A read-only property will only have a getter method, and its value is set when the document
154 163
 is read from the database. You can however update a read-only attribute using the `write_attribute` method:
@@ -380,7 +389,7 @@ Use pagination as follows:
380 389
 
381 390
 ### Design Documents and Views
382 391
 
383  
-Views must be defined in a Design Document for CouchDB to be able to perform searches. Each model therefore must have its own Design Document. Deciding when to update the model's design doc is a difficult issue, as in production you don't want to be constantly checking for updates and in development maximum flexability is important. CouchRest Model solves this issue by providing the `auto_update_design_doc` configuration option and is enabled by default.
  392
+Views must be defined in a Design Document for CouchDB to be able to perform searches. Each model therefore must have its own Design Document. Deciding when to update the model's design doc is a difficult issue, as in production you don't want to be constantly checking for updates and in development maximum flexability is important. CouchRest Model solves this issue by providing the `auto_update_design_doc` configuration option and is true by default.
384 393
 
385 394
 Each time a view or other design method is requested a quick GET for the design will be sent to ensure it is up to date with the latest changes. Results are cached in the current thread for the complete design document's URL, including the database, to try and limit requests. This should be fine for most projects, but dealing with multiple sub-databases may require a different strategy.
386 395
 
@@ -408,7 +417,7 @@ If you're dealing with multiple databases, using proxied models, or databases th
408 417
         end
409 418
       end
410 419
       def self.update_design_docs(db)
411  
-        CouchRest::Model::Base.subclasses.each{|klass| klass.save_design_doc!(db) if klass.respond_to?(:save_design_doc!(db)}
  420
+        CouchRest::Model::Base.subclasses.each{|klass| klass.save_design_doc!(db) if klass.respond_to?(:save_design_doc!}
412 421
       end
413 422
     end
414 423
 
@@ -599,8 +608,8 @@ To set for a specific model:
599 608
 Options currently avilable are:
600 609
 
601 610
  * `mass_assign_any_attribute` - false by default, when true any attribute may be updated via the update_attributes or attributes= methods.
602  
- * `model_type_key` - 'couchrest-type' by default, is the name of property that holds the class name of each CouchRest Model.
603  
- * `auto_update_design_doc` - true by default, every time a view is requested and this option is enabled, a quick check will be performed to ensure the model's design document is up to date. When disabled, you'll need to perform the updates manually. Typically, this option should be enabled in development, and disabled in production. See the View section for more details.
  611
+ * `model_type_key` - 'model' by default, is the name of property that holds the class name of each CouchRest Model.
  612
+ * `auto_update_design_doc` - true by default, every time a view is requested and this option is true, a quick check will be performed to ensure the model's design document is up to date. When disabled, you're design documents will never be updated automatically and you'll need to perform updates manually. Results are cached on a per-database and per-design basis to help lower the number of requests. See the View section for more details.
604 613
 
605 614
 
606 615
 ## Notable Issues
3  history.txt
... ...
@@ -1,5 +1,8 @@
1 1
 == 1.1.0.beta3
2 2
 
  3
+* Major changes:
  4
+  * Default CouchRest Model type field now set to 'model' instead of 'couchrest-type'.
  5
+
3 6
 * Minor enhancements:
4 7
   * Adding "couchrest-hash" to Design Docs with aim to improve view update handling.
5 8
   * Major changes to the way design document updates are handled internally.
2  lib/couchrest/model/configuration.rb
@@ -13,7 +13,7 @@ module Configuration
13 13
         add_config :auto_update_design_doc
14 14
 
15 15
         configure do |config|
16  
-          config.model_type_key = 'couchrest-type' # 'model'?
  16
+          config.model_type_key = 'model' # was 'couchrest-type'
17 17
           config.mass_assign_any_attribute = false
18 18
           config.auto_update_design_doc = true
19 19
         end
1  lib/couchrest/model/properties.rb
@@ -116,6 +116,7 @@ def set_attributes(hash)
116 116
       module ClassMethods
117 117
 
118 118
         def property(name, *options, &block)
  119
+          raise "Invalid property definition, '#{name}' already used for CouchRest Model type field" if name.to_s == model_type_key.to_s
119 120
           opts = { }
120 121
           type = options.shift
121 122
           if type.class != Hash
4  spec/couchrest/design_doc_spec.rb
@@ -17,11 +17,11 @@
17 17
     end
18 18
 
19 19
     it "should calculate a consistent checksum for model" do
20  
-      WithTemplateAndUniqueID.design_doc.checksum!.should eql('7786018bacb492e34a38436421a728d0')
  20
+      WithTemplateAndUniqueID.design_doc.checksum!.should eql('ff6fa2eaf774397391942d51428c1fe2')
21 21
     end
22 22
 
23 23
     it "should calculate checksum for complex model" do
24  
-      Article.design_doc.checksum!.should eql('1e6c315853cd5ff10e5c914863aee569')
  24
+      Article.design_doc.checksum!.should eql('fb65c06a76b6141529e31e894ad00b1a')
25 25
     end
26 26
 
27 27
     it "should cache the generated checksum value" do
2  spec/couchrest/designs/view_spec.rb
@@ -74,7 +74,7 @@ class DesignViewModel < CouchRest::Model::Base
74 74
       it "should auto generate mapping from name" do
75 75
         lambda { @klass.create(DesignViewModel, 'by_title') }.should_not raise_error
76 76
         str = @design_doc['views']['by_title']['map']
77  
-        str.should include("((doc['couchrest-type'] == 'DesignViewModel') && (doc['title'] != null))")
  77
+        str.should include("((doc['model'] == 'DesignViewModel') && (doc['title'] != null))")
78 78
         str.should include("emit(doc['title'], 1);")
79 79
         str = @design_doc['views']['by_title']['reduce']
80 80
         str.should include("return sum(values);")
3  spec/couchrest/property_spec.rb
@@ -55,6 +55,9 @@
55 55
     card.calias.name.should == ["Aimonetti"]
56 56
   end
57 57
 
  58
+  it "should raise error if property name coincides with model type key" do
  59
+    lambda { Person.property(Person.model_type_key) }.should raise_error(/already used/)
  60
+  end
58 61
 
59 62
   it "should be auto timestamped" do
60 63
     @card.created_at.should be_nil

0 notes on commit bc4c871

Please sign in to comment.
Something went wrong with that request. Please try again.