Monday 13 March 2017

Where have I gone wrong here? (querying/schema)

I know I'm missing something.My basic db structure diagrammed is here and my migration reflects that:exports.up = function(knex, Promise) { return Promise.all([ knex.schema.createTableIfNotExists('riders', function(table) { table.increments('id').primary() table.string('email') table.string('password') table.integer('most_ridden_train_id') .references('id') .inTable('trains') }), knex.schema.createTableIfNotExists('trains', function(table){ table.increments('id').primary() table.string('destination') table.integer('passenger_count') .defaultTo(0) }), knex.schema.createTableIfNotExists('train_riders', function(table){ table.increments('id').primary() table.integer('train_id') .references('id') .inTable('train') table.integer('rider_id') .references('id') .inTable('riders') table.timestamps() }) ]) }; exports.down = function(knex, Promise) { return Promise.all([ knex.schema.dropTable('trains'), knex.schema.dropTable('train_riders'), knex.schema.dropTable('riders') ]) }; I've been adding trains and riders and that's been working so for but then came time to update the most_ridden_train_id for the riders now that I've got a few trains, I'm using Objection so I used this:ben // instance of rider .$query() .patchAndFetch({ most_ridden_train_id: 2 }) .then((d) => { console.log("updated rider: ben") }) .catch((er) => { console.log(er) }) // { error: update "riders" set where "riders"."id" = $1 and "riders"."id" = $2 - syntax error at or near "where" //... So that's the error I get there. I know it has something to do with the schema because if I do this, then I don't get an error:ben // instance of rider .$query() .patchAndFetch({ email: "newEmail@gmail.com" }) .then((d) => { console.log("updated rider: ben") }) .catch((er) => { console.log(er) }) // updated rider: ben I bet it's something obvious and I'm just blocked. Thanks for any help!!

Submitted March 13, 2017 at 02:51PM by coderbee

No comments:

Post a Comment