-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
this.belongsTo is not a function #3
Comments
how have you created the user variable ? |
Forgot that! Here it is: let user
try {
user = yield User.find(request.param('id'))
} catch (e) {
response.notFound()
return
}
let opinion = new Opinion
opinion.liked = request.input('liked')
try {
opinion.user().associate(user)
yield opinion.create()
response.created()
} catch (e) {
response.internalServerError()
} |
also can you tell what error you get ? |
I get the title's error: |
This is wierd , let me reproduce it |
All worked great for me , sharing my code const user = yield User.find(1)
if(Object.keys(user.attributes).length === 0){
return 'Not found'
}
const opinion = new Opinion
opinion.user().associate(user)
const created = yield opinion.create()
if(created && created[0]) {
return 'All Good'
}
return 'Sorry unable to save your opinion' Couple of things to note here
|
Weird. I keep having the same error. Any ideas on what could it be? Thanks for the notes btw. |
what version of lucid u using ? |
1.0.2 |
Ohhhh , relationships have been introduced in |
Just updated here and now it works! My bad, sorry about that. |
No issues , docs needs to have upgrade section |
on |
I'm having the same issue. "@adonisjs/lucid": "^6.1.3", |
I've just had this issue with two relationships in which none were named 'foreigntable_primarykey'; both were just 'foreigntable'. I tried creating a new column in my DB with the expected naming system and it worked. Update: The is a big problem for me, as I am working with legacy code alongside sharing this database and I should not modify the current database structure. |
@thetutlage I'm in a similar condition. Any resolution for this? |
I'm trying the basic example shown in the docs but I'm getting the title error. The code I'm running is as follows:
And using like:
Should I create it before associating?
The text was updated successfully, but these errors were encountered: