Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0-10 -> page 1
- 10-20 -> page 2
- 20-30 -> page 3
- var activityType = db.Model.extend({
- tableName: 'activitytypes',
- hasTimestamps: false
- });
- var user = db.Model.extend({
- tableName: 'users',
- hasTimestamps: true,
- feed: function() {
- return this.hasMany(activity);
- },
- });
- var activity = db.Model.extend({
- tableName: 'activities',
- hasTimestamps: true,
- userRelated : function() {
- return this.belongsTo(user,'related_user');
- },
- activityTypes: function() {
- return this.belongsTo(activityType);
- },
- });
- user.where({
- id: 43
- }).fetchAll({
- withRelated: ['feed.userRelated', 'feed.activityTypes']
- }).then(function(data) {
- data = data.toJSON();
- res.send(data);
- });
- router.get('/feed/:page'); -> This is how I pass page number to requested variable.
- var requested = req.params.page;
- var start = 10 * (requested - 1);
- user.query(function(qb) {
- qb.where({
- id: 43
- });
- }).fetchAll({
- withRelated: [{
- 'feed.userRelated',
- 'feed.activityTypes',
- 'feed': function(limitNow) {
- limitNow.offset(start).limit(10);
- }
- }]
- }).then(function(data) {
- data = data.toJSON();
- res.send(data);
- });
- SyntaxError: Unexpected token ,
- www-0 at exports.runInThisContext (vm.js:53:16)
- www-0 at Module._compile (module.js:414:25)
- www-0 at Object.Module._extensions..js (module.js:442:10)
- www-0 at Module.load (module.js:356:32)
- www-0 at Function.Module._load (module.js:311:12)
- www-0 at Function._load (/usr/local/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
- www-0 at Module.require (module.js:366:17)
- www-0 at require (module.js:385:17)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement