Permalink
Browse files

use table names for type instead of class.name.downcase, this should …

…be more consistent with other parts of datamapper AND respect table_name options
  • Loading branch information...
Wesley Beary
Wesley Beary committed Jul 21, 2008
1 parent 5dfa4b4 commit b429af76f6acccfd5c1a86b86e346d54a3572060
@@ -14,7 +14,7 @@ module Resource
# Converts a Resource to a JSON representation.
def to_json(dirty = false)
property_list = self.class.properties.select { |key, value| dirty ? self.dirty_attributes.key?(key) : true }
- inferred_fields = {:type => self.class.name.downcase}
+ inferred_fields = {:type => self.class.storage_name(repository.name)}
return (property_list.inject(inferred_fields) do |accumulator, property|
accumulator[property.field] =
unless property.type.respond_to?(:dump)
@@ -134,7 +134,7 @@ def read_many(query)
end
end
end
- elsif doc['type'] && doc['type'].downcase == query.model.name.downcase
+ elsif doc['type'] && doc['type'] == query.model.storage_name(repository.name)
data = doc
Collection.new(query) do |collection|
collection.load(
@@ -153,7 +153,7 @@ def read_one(query)
if doc['rows'] && !doc['rows'].empty?
data = doc['rows'].first['value']
elsif !doc['rows']
- data = doc if doc['type'] && doc['type'].downcase == query.model.name.downcase
+ data = doc if doc['type'] && doc['type'] == query.model.storage_name(repository.name)
end
if data
query.model.load(
@@ -209,7 +209,7 @@ def ad_hoc_request(query)
request.body =
%Q({"map":
"function(doc) {
- if (doc.type == '#{query.model.name.downcase}') {
+ if (doc.type == '#{query.model.storage_name(repository.name)}') {
emit(#{key}, doc);
}
}"
@@ -239,7 +239,7 @@ def ad_hoc_request(query)
request.body =
%Q({"map":
"function(doc) {
- if (doc.type == '#{query.model.name.downcase}' && #{conditions.join(" && ")}) {
+ if (doc.type == '#{query.model.storage_name(repository.name)}' && #{conditions.join(" && ")}) {
emit(#{key}, doc);
}
}"
@@ -22,9 +22,9 @@ class User
property :location, JsonObject
# creates methods for accessing stored/indexed views in the CouchDB database
- view :by_name, { "map" => "function(doc) { if (doc.type == 'user') { emit(doc.name, doc); } }" }
- view :by_age, { "map" => "function(doc) { if (doc.type == 'user') { emit(doc.age, doc); } }" }
- view :count, { "map" => "function(doc) { if (doc.type == 'user') { emit(null, 1); } }",
+ view :by_name, { "map" => "function(doc) { if (doc.type == 'users') { emit(doc.name, doc); } }" }
+ view :by_age, { "map" => "function(doc) { if (doc.type == 'users') { emit(doc.age, doc); } }" }
+ view :count, { "map" => "function(doc) { if (doc.type == 'users') { emit(null, 1); } }",
"reduce" => "function(keys, values) { return sum(values); }" }
before :create do

0 comments on commit b429af7

Please sign in to comment.