-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
table name "xxx" specified more than once - objection #17
Comments
Sorry for the long response. |
Ah, the fix should be trivial if objection provides an api to check whether the table was joined before and retrieve its alias |
No worries. I just do some testing and experimenting. If it is ok for you, i'll report my experiences here. If you give me a hint on how you would solve this issue, i can try to create a pull request. |
Yes, report please everything here |
I think at this point we need to add additional check that ensures relation was not joined before |
When a relation was already joined with `withGraphJoined`, ucast was adding the relation a second time. Now a check for the relation is performed. fixes stalniy#17
Hey, one small issue. The existing tests do all work, but to test The error is: Error: I'm not sure how to continue from here. Not sure if it makes sense to add integration tests to ucast/sql? What would you propose? |
Can we check existence of joined relation without waiting for metadata fetching? Maybe on knex level? Just don’t understand why we need this |
Sorry, I was a bit in a hurry yesterday. I should have added more information and not waste your time. Here is everything i figured out so far: I created a test like this: it('doest not join relation again when condition is set on relation field and already joined', () => {
const condition = new FieldCondition('eq', 'projects.name', 'test')
const userQuery = User.query().withGraphJoined('[projects]')
const query = interpret(condition, userQuery)
expect(query.toKnexQuery().toString()).to.equal(linearize`
select "users".*
from "users"
inner join "projects" on "projects"."user_id" = "users"."id"
where "projects"."name" = 'test'
`.trim())
}) This results in the error: If I add the const knex = Knex({ client: 'pg' })
initialize(knex, [User, Project]).then() it results in an timeout, because the initialize method tries to connect to the database to retrieve the metadata. So I'm not sure how to properly test the resulting sql from an objection.js query with |
I'm using you gist code to check casl rights directly at the database. But when i do a
eager
orwithGraphJoined
theinterpret
function will add a second join for the relation, leading to the errortable name "xxx" specified more than once - objection
. My ability checks if the user id is either TechnicalContact or AccountOwner.I see there is a sample which seems to prevent adding a new relation join, but this is not available with objection.
My code:
Error:
Results in an sql query like this:
table name "technical_contact" specified more than once
and the sql looks somewhat like this:
The text was updated successfully, but these errors were encountered: