Permalink
Browse files

added query support for 'ref' and 'embed'

  • Loading branch information...
1 parent 69a8b2d commit 92b54105d9e305a19b346f32a9663e9114e0e957 @funkytek funkytek committed Sep 17, 2013
Showing with 17 additions and 9 deletions.
  1. +13 −6 lib/main.coffee
  2. +2 −1 package.json
  3. +1 −1 test/config/config.coffee
  4. +1 −1 test/main.coffee
View
@@ -1,6 +1,7 @@
async = require 'async'
{Schema} = require 'mongoose'
Hookify = require 'hookify'
+_ = require 'lodash'
module.exports =
@@ -40,10 +41,16 @@ module.exports =
rand: (model) -> @collection[model][Math.floor(Math.random()*@collection[model].length)]
- ref: (model) ->
- # just ObjectId
- return @rand(model)._id
+ ref: (model, query) ->
+ if query?
+ return _.find(@collection[model], query)._id
+ else
+ # just ObjectId
+ return @rand(model)._id
- embed: (model) ->
- # randomize
- return @rand(model)
+ embed: (model, query) ->
+ if query?
+ return _.find @collection[model], query
+ else
+ # randomize
+ return @rand(model)
View
@@ -10,7 +10,8 @@
"coffee-script": "*",
"async": "*",
"mongoose": "*",
- "hookify": "0.0.1"
+ "hookify": "0.0.1",
+ "lodash": "~2.0.0"
},
"devDependencies": {
"mocha": "*",
@@ -6,4 +6,4 @@ module.exports =
db:
url: process.env.MONGODB or "mongodb://localhost/#{appName}"
paths:
- models: path.resolve './test/models'
+ models: path.resolve './test/models/*'
View
@@ -38,7 +38,7 @@ module.exports =
name: "The Iceman"
date: "5/15/13"
imgUrl: "http://api.ning.com/files/ysdCY8Oh2FFFqeGsBQ6Qpeb6eJZ6ytFvsVN2r0QDqPaPnwC9Lu4NQSl6Mcch4lABkVqYrX-jUoZa8xK2ccGDnXbwANQcPvf-/iceman.jpg?size=173&crop=1:1"
- location: @seed.ref 'Location'
+ location: @seed.ref 'Location', {name: "Scottsdale Fashion Square"}
]
"given hooks": =>

0 comments on commit 92b5410

Please sign in to comment.