Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何查找未与吃水线ORM连接的记录_Mysql_Node.js_Sails.js_Waterline - Fatal编程技术网

Mysql 如何查找未与吃水线ORM连接的记录

Mysql 如何查找未与吃水线ORM连接的记录,mysql,node.js,sails.js,waterline,Mysql,Node.js,Sails.js,Waterline,我正在使用node.js框架sailsjs及其内置的ormwaterline来进行一个类似Tinder的项目 我不知道如何编写查询以获取未联接的记录。在我的例子中,当一个用户“喜欢”或“不喜欢”另一个用户的配置文件时,我希望喜欢的配置文件不再显示 我如何做到这一点?这就是我迄今为止所尝试的: Cat.query('select cat.* from cat left outer join vote on cat.id = vote.owner where vote.owner is null A

我正在使用
node.js
框架sailsjs及其内置的ormwaterline来进行一个类似Tinder的项目

我不知道如何编写查询以获取未联接的记录。在我的例子中,当一个用户“喜欢”或“不喜欢”另一个用户的配置文件时,我希望喜欢的配置文件不再显示

我如何做到这一点?这就是我迄今为止所尝试的:

Cat.query('select cat.* from cat left outer join vote on cat.id = vote.owner where vote.owner is null AND cat.id !='+req.session.User.id, function (err, results) {
        if (err) return res.serverError(err);
        res.send('Yes');
        console.log(results);
    });

如果我没弄错的话,Cat是用户档案吗? 因此,我们需要以下配置文件:

  • 不属于当前用户(
    cat.id!==req.session.user.id
  • 当前用户不喜欢或不喜欢

    var query = 'select cat.* ' + 
    ' from cat left join vote on' + 
      // joining votes for current user
      ' cat.id = vote.catId and vote.owner = ' + req.session.User.id +
    ' where' + 
    // filtering out the Cat with current user Id (if needed)
    ' cat.id <> ' + req.session.User.id +
    ' and' + 
    // leaving only records with empty vote id(meaning there's no corresponding vote record)
    ' vote.id is null';
    
    var query='select cat.*'+
    '从cat left加入对'+
    //为当前用户加入投票
    “cat.id=vote.catId和vote.owner=”+req.session.User.id+
    '何处'+
    //筛选出具有当前用户Id的Cat(如果需要)
    “cat.id”+req.session.User.id+
    '和'+
    //只留下投票id为空的记录(意味着没有相应的投票记录)
    “vote.id为空”;
    
  • 纯SQL可获得更清晰的视图:

    select cat.* from cat left join vote on 
      cat.id = vote.catId and vote.owner = :userId
    where 
      cat.id <> :userId 
    and
      vote.id is null
    
    从cat left中选择cat.*加入投票
    cat.id=vote.catId和vote.owner=:userId
    哪里
    cat.id:userId
    和
    vote.id为空
    

    我们从当前用户为其所做的cat表中选择all记录。然后只留下缺少投票的记录和当前用户id的记录,我们如何帮助您编写查询而不使用任何示例代码?