C2FO / patio

Idiomatic database toolkit

Home Page:http://c2fo.github.io/patio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Select with join

opened this issue · comments

Hi, I want to do a select on a column 'idMessage' which is in 2 tables that have joined, how can I do that ?

    var Device = db.from('Device');
    var DevicePushIDStateMessage = Device.join('PushID', {idDevice: sql.macAddress}).join('State', {idPush: sql.deviceToken}).join('Message', {idMessage: sql.idMessage});

    DevicePushIDStateMessage.first({macAddress: macAddress, idMessage: idMessage}).then(function(object){
        if(object){
            util.log('not null');
        } else {
            util.log('null');
        }
    });

when I made the test, the message 'null' or 'not null' doesn't show.

thanks

try adding an errback to .then function to see if an error is being thrown

    DevicePushIDStateMessage.first({macAddress: macAddress, idMessage: idMessage}).then(function(object){
        if(object){
            util.log('not null');
        } else {
            util.log('null');
        }
    }, function(err){
      console.log(err);
   });