Replies: 2 comments 3 replies
-
why not try finding the contact with the ID AND user id? Might be easier and better? Contact.query().where('id', contactId).andWhere('user_id', auth.user.id) |
Beta Was this translation helpful? Give feedback.
1 reply
-
@aikrom Don't know if you resolved or moved on. But if you still have this problem, you can try this query. export default class TestController extends BaseModel {
public async delete({ auth, bouncer, request }: HttpContextContract) {
const contactId = request.param('contact_id')
const contact = await auth.user!.related('contacts').query().where('contacts.id', contactId).firstOrFail()
await contact.delete()
return 'OK'
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a User and Contact model. The relationship between these models is many-to-many because Contact may have relationships with other models in the future.
User:
Contact:
When I run the code below to find a contact:
I am getting an error:
The contact table name does not prefixed in the SQL query. I think it's a bug, but I'm not sure. Has anyone come across this situation?
Beta Was this translation helpful? Give feedback.
All reactions