Permalink
Browse files

made fields part of metadata

  • Loading branch information...
1 parent 53ab7d8 commit 0b8c333bdf48dea135b5033e6ae597a293f77cd4 @lancejpollard lancejpollard committed Apr 7, 2012
@@ -129,7 +129,7 @@ Tower.Model.Attribute = (function() {
};
function Attribute(owner, name, options, block) {
- var key, normalizedKey, serializer, validations, _ref;
+ var index, key, normalizedKey, serializer, validations, _ref;
if (options == null) options = {};
this.owner = owner;
this.name = key = name;
@@ -178,6 +178,11 @@ Tower.Model.Attribute = (function() {
this._default = [];
}
}
+ if (this.type === 'Geo' && !options.index) {
+ index = {};
+ index[name] = "2d";
+ options.index = index;
+ }
this.get = options.get || (serializer ? serializer.from : void 0);
this.set = options.set || (serializer ? serializer.to : void 0);
if (this.get === true) {
@@ -7,7 +7,7 @@ Tower.Model.Attributes = {
},
fields: function() {
var fields, name, names, options, _i, _len, _ref;
- fields = this._fields || (this._fields = {});
+ fields = this.metadata().fields;
switch (arguments.length) {
case 0:
fields;
@@ -62,7 +62,7 @@ Tower.Model.Conversion = {
controllerName: controllerName,
indexes: indexes,
validators: validators,
- fields: {}
+ fields: fields
};
}
},
@@ -107,6 +107,11 @@ class Tower.Model.Attribute
else if @type == 'Array'
@_default = []
+ if @type == 'Geo' && !options.index
+ index = {}
+ index[name] = "2d"
+ options.index = index
+
@get = options.get || (serializer.from if serializer)
@set = options.set || (serializer.to if serializer)
@@ -22,7 +22,7 @@ Tower.Model.Attributes =
#
# @return [Object]
fields: ->
- fields = @_fields ||= {}
+ fields = @metadata().fields
switch arguments.length
when 0
@@ -79,7 +79,7 @@ Tower.Model.Conversion =
controllerName: controllerName
indexes: indexes
validators: validators
- fields: {}
+ fields: fields
# A label for this model when rendered to a string.
#
@@ -396,16 +396,16 @@ class Tower.Model.Criteria extends Tower.Class
@
toJSON: ->
- where: @_where
- order: @_order
- offset: @_offset
- limit: @_limit
- fields: @_fields
- except: @_except
- includes: @_includes
- joins: @_joins
+ where: @_where
+ order: @_order
+ offset: @_offset
+ limit: @_limit
+ fields: @_fields
+ except: @_except
+ includes: @_includes
+ joins: @_joins
eagerLoad: @_eagerLoad
- near: @_near
+ near: @_near
# Compiled result from the {#where} arguments.
#
@@ -69,8 +69,10 @@ describeWith = (store) ->
async.forEachSeries data, iterator, done
test 'near', (done) ->
- App.Address.near(coordinates.paris).all (error, records) =>
- #console.log _.map records, (i) -> i.get('coordinates')
+ paris = coordinates.paris
+
+ App.Address.near(lat: paris.latitude, lng: paris.longitude).all (error, records) =>
+ assert.equal records.length, 7
done()
describe 'within', ->
@@ -79,3 +81,4 @@ describeWith = (store) ->
test 'within(distance: 5, unit: "miles")'
describeWith(Tower.Store.MongoDB)
+# describeWith(Tower.Store.Memory)
View
@@ -68,10 +68,8 @@ Tower.Controller::redirectTo = (options = {}) ->
app = Tower.Application.instance()
before (done) ->
- app.initialize =>
- require "#{Tower.root}/app/models/address"
-
- App.Address.store().collection().ensureIndex {coordinates:"2d"}, done
+ app.initialize done
+ # App.Address.store().collection().ensureIndex {coordinates:"2d"}, done
beforeEach (done) ->
#Tower.Application.instance().teardown()

0 comments on commit 0b8c333

Please sign in to comment.