خرید بک لینک

Vote count: 0

I am trying to retu a list of Users based on a search term I am receiving from the client. User hasMany Skills. I would like to retu all users by searching for the term in all the possible User fields this includes the Skill title.

my tables and relationships are in a db file this is why you will see db.Skill

User.hasMany(Skill, {foreignKey: 'mentorId'});


exports.userSearchMentors = function(req, res, term){
  db.User.findAll({
      where: {
        $or: [

      {
        useame: {
          $like: '%' + term + '%'
        }
      },
      {
        firstname: {
          $like: '%' + term + '%'
        }
      },
      {
        lastname: {
          $like: '%' + term + '%'
        }
      },
      {
        email: {
          $like: '%' + term + '%'
        }
      },
      {
        phone: {
          $like: '%' + term + '%'
        }
      },
      {
        description: {
          $like: '%' + term + '%'
        }
      }

    ]
  },
  $or: [{
  include : [{
               model : db.Skill,
               where : { title : {
                 $like: '%' + term + '%'}
                 }
            }]
  }]
})
.then(function(mentors){
    console.log("line 58: list of found mentors by term");
    res.status(200).send(mentors)
})
.catch(function(err){
    console.error(err.message);
    res.status(500).send(err.message);
});

asked 45 secs ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 11 مرداد 1395 ساعت: 2:42

صفحه بندی