0

I have a Job model that searches a table of jobs. The table was created using rails, and I set 'migrate' to 'safe' in the Job model. I have written out all the attributes in the model. I cannot get basic functions to work in the sails console. I have three jobs in the table, with ids 1,2, and 3. When I execute:

sails> Job.findOneById(1).done(function(err,job){console.log(j.id)})

It poops out on me. The sails console crashes (super annoying). The output looks like this:

sails> Job.findOneById(1).done(function(err,job){console.log(j.id)})
undefined
sails> 
/home/redmage/tac/node_modules/sails-postgresql/lib/query.js:544
    var type = self._schema[key].type;
                                ^
TypeError: Cannot read property 'type' of undefined
    at /home/redmage/tac/node_modules/sails-postgresql/lib/query.js:544:33
    at Array.forEach (native)
    at Query.cast (/home/redmage/tac/node_modules/sails-postgresql/lib/query.js:541:23)
    at /home/redmage/tac/node_modules/sails-postgresql/lib/adapter.js:372:32
    at Array.forEach (native)
    at __FIND__ (/home/redmage/tac/node_modules/sails-postgresql/lib/adapter.js:371:23)
    at Query.handleReadyForQuery (/home/redmage/tac/node_modules/sails-postgresql/node_modules/pg/lib/query.js:84:10)
    at null.<anonymous> (/home/redmage/tac/node_modules/sails-postgresql/node_modules/pg/lib/client.js:159:19)
    at EventEmitter.emit (events.js:117:20)
    at null.<anonymous> (/home/redmage/tac/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:97:12)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_readable.js:127:10)
    at TCP.onread (net.js:528:21)

Here is the ORM for Job. It is very basic:

module.exports = {

  //VERY IMPORTANT:
  migrate: 'safe', 

  tableName: 'jobs',

  attributes: {

  }
}
RedMage
  • 1,126
  • 1
  • 9
  • 21
  • 1
    Looks like an adapter version mismatch to me. What version of Sails and sails-postgres are you running? – sgress454 Mar 21 '14 at 01:57
  • sails-postgres is 0.9.7, sails is 0.9.11 – RedMage Mar 21 '14 at 14:53
  • Works fine for me with a basic test...try removing `sails-postgresql`, `npm cache clear` and `npm install sails-postgresql` again? Also, what does your Job model look like in Sails? – sgress454 Mar 21 '14 at 15:40
  • now it's saying "connection to Postgresql: error: password authentication failed for user 'myuser'". I don't recall if this happened before – RedMage Mar 21 '14 at 17:35
  • 1
    Check your `config/adapters.js` and make sure the Postgres connection looks right? – sgress454 Mar 21 '14 at 17:36
  • Looks good: localDevDatabase: { module: 'sails-postgresql', host: 'localhost', database: 'development', user: 'myuser', password: 'password', port: 5432, pool: false } – RedMage Mar 21 '14 at 17:39
  • Do I need to use 'sudo' when installing sails-postgresql? – RedMage Mar 21 '14 at 17:40
  • 1
    No, but it is certainly odd that it's saying that authentication failed if you definitely have the right username, password, host and database set. Double check by logging in with the console? – sgress454 Mar 21 '14 at 17:41
  • Yah, I can log in via psql. It's very, very strange. I set to logging level in sails to 'verbose', but now the only different thing is it says, twice, that it is enabling coffeescript – RedMage Mar 21 '14 at 17:45
  • BTW, I just reinstalled sails, so now it's version 0.9.13 instead of 0.9.11. Maybe I should log an issue with the sails-postgresql creator... – RedMage Mar 21 '14 at 17:46
  • Get this: if I change the user name in the config, then the error does not reflect that change. However, if I do 'sudo sails console', then it gives the same error, only for user 'root' – RedMage Mar 21 '14 at 17:56
  • 1
    Ah, it's the db user environment variable. Try `DB_USER= sails lift`, where `` is whatever Linux user you set up the database with. – sgress454 Mar 21 '14 at 17:59
  • when I set DB_USER, then run sail lift, it blows up on a grunt task: error: Grunt :: Warning: Clean operation failed. Use --force to continue. Running "clean:dev" (clean) task Cleaning ".tmp/public"... ERROR – RedMage Mar 21 '14 at 18:20
  • For some reason, that .tmp/public is owned by root. When I change the owner to myself, then that prior grunt error disappears. The sails console error still persists. – RedMage Mar 21 '14 at 18:23
  • I'm really not sure what is going on. I went home and tried on my home PC and everything is fine. Though, I'm running 0.10.0-rc4 at home. I'll try upgrading on my machine at work later and let you know. Thank you for all the help. – RedMage Mar 21 '14 at 21:37

0 Answers0