-
Notifications
You must be signed in to change notification settings - Fork 642
Description
I have a query that looks similar to this:
Thing.query().first().select(
"thingId", "creationTime", "author.emailAddress"
).joinRelation("author" /* Join on users table */ ).where({
"thingId": thingId
}).then(thing => doStuff(thing))Both the thing and user tables have a creationTime column. When I try to express the query like above I get an error column reference "creationTime" is ambiguous.
One solution would be to do this, but I really don't want to because it's verbose and repetitive and I'd have to do it in lots of places. It wouldn't help maintainability at all.
Thing.query().first().select(
"thingId", "thingSchemaName.thingTableName.creationTime", "author.emailAddress"
).joinRelation("author" /* Join on users table */ ).where({
"thingId": thingId
}).then(thing => doStuff(thing))What I would very much like to do and would expect to be able to do - except I haven't worked out any way how - is to select the model table with an alias. Something nice and sensible and readable like
Thing.query().as("thing").first().select(
"thing.thingId", "thing.creationTime", "author.emailAddress"
).joinRelation("author" /* Join on users table */ ).where({
"thing.thingId": thingId
}).then(thing => doStuff(thing))Or, it would be quite nice if objection was able to automagically prepend the models' table name to selected columns that don't otherwise specify.
What's the best way to fix this?