Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. 0-10 -> page 1
  2. 10-20 -> page 2
  3. 20-30 -> page 3
  4.  
  5. var activityType = db.Model.extend({
  6. tableName: 'activitytypes',
  7. hasTimestamps: false
  8. });
  9.  
  10. var user = db.Model.extend({
  11. tableName: 'users',
  12. hasTimestamps: true,
  13.  
  14. feed: function() {
  15. return this.hasMany(activity);
  16. },
  17. });
  18.  
  19. var activity = db.Model.extend({
  20. tableName: 'activities',
  21. hasTimestamps: true,
  22.  
  23. userRelated : function() {
  24. return this.belongsTo(user,'related_user');
  25. },
  26.  
  27. activityTypes: function() {
  28. return this.belongsTo(activityType);
  29. },
  30. });
  31.  
  32. user.where({
  33. id: 43
  34. }).fetchAll({
  35. withRelated: ['feed.userRelated', 'feed.activityTypes']
  36. }).then(function(data) {
  37. data = data.toJSON();
  38. res.send(data);
  39. });
  40.  
  41. router.get('/feed/:page'); -> This is how I pass page number to requested variable.
  42. var requested = req.params.page;
  43. var start = 10 * (requested - 1);
  44.  
  45. user.query(function(qb) {
  46. qb.where({
  47. id: 43
  48. });
  49. }).fetchAll({
  50. withRelated: [{
  51. 'feed.userRelated',
  52. 'feed.activityTypes',
  53. 'feed': function(limitNow) {
  54. limitNow.offset(start).limit(10);
  55. }
  56. }]
  57. }).then(function(data) {
  58. data = data.toJSON();
  59. res.send(data);
  60. });
  61.  
  62. SyntaxError: Unexpected token ,
  63. www-0 at exports.runInThisContext (vm.js:53:16)
  64. www-0 at Module._compile (module.js:414:25)
  65. www-0 at Object.Module._extensions..js (module.js:442:10)
  66. www-0 at Module.load (module.js:356:32)
  67. www-0 at Function.Module._load (module.js:311:12)
  68. www-0 at Function._load (/usr/local/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
  69. www-0 at Module.require (module.js:366:17)
  70. www-0 at require (module.js:385:17)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement