We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I would like to be able to UPDATE models by calling saveAll() on a document. Similar to the example below taken from the thinky.io docs:
var User = thinky.createModel("User", { id: type.string(), name: type.string() }); var Account = thinky.createModel("Account", { id: type.string(), sold: type.number(), userId: type.string() }); User.hasOne(Account, "account", "id", "userId"); User.get("0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a") .getJoin({account: true}).run().then(function(user) { /* * var user = { * id: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * name: "Michel", * account: { * id: "3851d8b4-5358-43f2-ba23-f4d481358901", * userId: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * sold: 2420 * } * } */ user.account = null; user.saveAll({account: true}).then(function(user) { /* * var user = { * id: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * name: "Michel", * } */ Account.get("3851d8b4-5358-43f2-ba23-f4d481358901").run() .then(function(account) { /* * // The foreign key in account was deleted. * var account: { * id: "3851d8b4-5358-43f2-ba23-f4d481358901", * sold: 2420 * } */ }); }); }):
However it would work like this:
var User = thinky.createModel("User", { id: type.string(), name: type.string() }); var Account = thinky.createModel("Account", { id: type.string(), sold: type.number(), userId: type.string() }); User.hasOne(Account, "account", "id", "userId"); User.get("0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a") .getJoin({account: true}).run().then(function(user) { /* * var user = { * id: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * name: "Michel", * account: { * id: "3851d8b4-5358-43f2-ba23-f4d481358901", * userId: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * sold: 2420 * } * } */ user.account.sold = 888; user.saveAll({account: true}).then(function(user) { /* * var user = { * id: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * name: "Michel", * account: { * id: "3851d8b4-5358-43f2-ba23-f4d481358901", * userId: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * sold: 888 * } * } */ Account.get("3851d8b4-5358-43f2-ba23-f4d481358901").run() .then(function(account) { /* * // The property is updated * var account: { * id: "3851d8b4-5358-43f2-ba23-f4d481358901", * userId: "0e4a6f6f-cc0c-4aa5-951a-fcfc480dd05a", * sold: 888, * } */ }); }); }):
Is this possible to do?
The text was updated successfully, but these errors were encountered:
I might be wrong, but I believe that is exactly how it works. Have you tried it?
Sorry, something went wrong.
No branches or pull requests
Question
I would like to be able to UPDATE models by calling saveAll() on a document. Similar to the example below taken from the thinky.io docs:
However it would work like this:
Is this possible to do?
The text was updated successfully, but these errors were encountered: