Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. Fish.find is not a function at model.UserSchema.methods.fishes
  2.  
  3. // Require mongoose to create a model.
  4. var mongoose = require('mongoose'),
  5. User = require('./user.js');
  6.  
  7. // Create a schema of your model
  8. var fishSchema = new mongoose.Schema({
  9. name: String,
  10. category: String,
  11. user: { type: mongoose.Schema.Types.ObjectId, ref:'User' }
  12. });
  13.  
  14. // Create the model using your schema.
  15. var Fish = mongoose.model('Fish', fishSchema);
  16.  
  17. // Export the model of the Fish.
  18. module.exports = Fish;
  19.  
  20. var mongoose = require('mongoose'),
  21. Schema = mongoose.Schema,
  22. bcrypt = require('bcrypt-nodejs'),
  23. Fish = require('./fish');
  24.  
  25. //||||||||||||||||||||||||||--
  26. // CREATE USER SCHEMA
  27. //||||||||||||||||||||||||||--
  28. var UserSchema = new Schema({
  29. name: { type: String, required: true },
  30. phoneNumber: {
  31. type: String,
  32. required: true,
  33. index: { unique: true },
  34. minlength: 7,
  35. maxlength: 10
  36. },
  37. password: { type: String, required: true, select: false }
  38. });
  39.  
  40.  
  41. // … some bcrypt stuff…
  42.  
  43. // Access user's fishes - THIS IS WHAT'S MESSING UP!!
  44. UserSchema.methods.fishes = function(callback) {
  45. Fish.find({user: this._id}, function(err, fishes) {
  46. callback(err, fishes);
  47. });
  48. };
  49.  
  50. module.exports = mongoose.model('User', UserSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement