vapor-community / mysql-provider

MySQL provider for the Vapor web framework.
MIT License
30 stars 12 forks source link

Can't update and save model #27

Closed iAlirezaKML closed 7 years ago

iAlirezaKML commented 7 years ago

I try to update a model and then saving it, but I'm getting this all the time:

{
    "code": 500,
    "error": true,
    "message": "Error: prepare(\"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \\'\\' at line 1\")",
    "metadata": null
}

I'm doing this:

model.justForFun = "serious"
try model.save()
return try JSON(node: [
    "status" : 200,
    "message" : "Success"
    ])

The model is valid, but something happens inside model.save(), when I logged, willUpdate() is called, but didUpdate() is not being called.

This is my config:

.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 5),
.Package(url: "https://github.com/vapor/mysql-provider.git", majorVersion: 1, minor: 1),

Thanks.

vzsg commented 7 years ago

Can you upload the sources of the model class? Especially the makeNode function would be interesting.

iAlirezaKML commented 7 years ago

@vzsg Thanks! I forgot to include id in the makeNode function. I know it's not the place, but I'm curious is there any built-in timestamp that I can use and not re-write it?

vzsg commented 7 years ago

I don't think there's a built-in solution for Vapor 1.x. If you look around, you can find blogposts like this (I found this today) with close to ready solutions.

If you want to discuss questions like this, you might want to consider joining the Vapor Slack team for better exposure. 😉