Running examples/express-ts/example-requests.sh on the 24-Dec-2017 code base gives me the following two errors. All other curls run fine. I haven't tried an earlier build.
# Get Silver Linings Playbook movie's actors.
curl "http://localhost:8641/movies/1/actors"
select `Person`.*, `Person_Movie`.`movieId` as `objectiontmpjoin0` from `Person` inner join `Person_Movie` on `Person`.`id` as `_expr`, `Person`.`id` as `columnName`, as `access` as `_reference`, `id` as `_column`, `Person` as `_table`, as `_cast`, `false` as `_toJson`, as `_as` = `Person_Movie`.`personId` as `_expr`, `Person_Movie`.`personId` as `columnName`, as `access` as `_reference`, `personId` as `_column`, `Person_Movie` as `_table`, as `_cast`, `false` as `_toJson`, as `_as` where `Person_Movie`.`movieId` in (1) - SQLITE_ERROR: near "as": syntax error
# Fetch Sylvester eagerly with relations. The eager expression is "[pets, children.[movies, pets]]" url encoded.
curl "http://localhost:8641/persons?minAge=60&eager=%5Bpets,children.%5Bmovies,pets%5D%5D"
select `Movie`.*, `Person_Movie`.`personId` as `objectiontmpjoin0` from `Movie` inner join `Person_Movie` on `Movie`.`id` as `_expr`, `Movie`.`id` as `columnName`, as `access` as `_reference`, `id` as `_column`, `Movie` as `_table`, as `_cast`, `false` as `_toJson`, as `_as` = `Person_Movie`.`movieId` as `_expr`, `Person_Movie`.`movieId` as `columnName`, as `access` as `_reference`, `movieId` as `_column`, `Person_Movie` as `_table`, as `_cast`, `false` as `_toJson`, as `_as` where `Person_Movie`.`personId` in (5, 6) - SQLITE_ERROR: near "as": syntax error
My knex versions:
Knex CLI version: 0.14.2
Local Knex version: 0.14.2
My apologies for not having the confidence to trouble-shoot this. I'm a long-time back-end Java and C dev with little SQL experience. (I decided that I better get to know objection better by playing with the examples before proceeding with my project.)
Confirmed. Also happens with the master version. Unfortunately everything typescript related has been contributed by the community and I cannot help you with that. Maybe @mceachen can take a look at this?
Looks like the express-es[6,7] and express-ts directories have drifted. I can successfully run the curl commands from express-ts against a server from the express-es6 directory. Diffing now.
the query from the es7 example is
SELECT `movie`.*,
`person_movie`.`personid` AS `objectiontmpjoin0`
FROM `movie`
INNER JOIN `person_movie`
ON `movie`.`id` = `person_movie`.`movieid`
WHERE `person_movie`.`personid` IN ( ?, ? )
the typescript version is
SELECT `movie`.*,
`person_movie`.`personid` AS `objectiontmpjoin0`
FROM `movie`
INNER JOIN `person_movie`
ON `movie`.`id` as `_expr`,
`movie`.`id` AS `columnname`,
AS `access` AS `_reference`,
`id` AS `_column`,
`movie` AS `_table`,
AS `_cast`,
`false` AS `_tojson`,
AS `_as` = `person_movie`.`movieid` AS `_expr`,
`person_movie`.`movieid` AS `columnname`,
AS `access` AS `_reference`,
`movieid` AS `_column`,
`person_movie` AS `_table`,
AS `_cast`,
`false` AS `_tojson`,
AS `_as`
WHERE `person_movie`.`personid` IN (?,
?)
@koskimas are these bogus fields from some sort of object reflection? I'm still poking.
I tried removing all fields from the Animal, Movie, and Person classes. The spurious INNER JOIN constraints are still produced.
~Ah, this is once again caused by two knex versions in the project --> instanceof doesn't work. We just need to find out why there are two of them this time.~
No it wasn't
Anyway, that's a ReferenceBuilder instance gone bad. For some reason its type isn't detected and it ends up used as a where object.
Something weird is happening in convertFunction function in ObjectionToKnexConvertingOperation.js file. I'm suspecting that isKnexJoinBuilder is failing for some reason. It could be the two knexes case after all, but I just don't see how.
It's probably this line in package.json:
"objection": "../..",
I feel like I've remove that at least twice from there 馃槃
Yeah it works if I use
"objection": "^0.9.4",
Using
"objection": "../.."
is a bad idea for another reason: the "../../" repo is the master branch and it may be partially broken or have breaking changes. Since there are not automatic tests for the example projects, I only check that they work when I make a new release.
@koskimas #692 fixes the ../.. dependency and re-synchronizes app and api so the queries are comparable (like the ORDER BY)
Thank you both for so quickly resolving this! I'll be traveling until Friday, so I'll check things out then.