Skip to content
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

existing record doesn't save! #31

Closed
redvex opened this issue Oct 6, 2012 · 3 comments
Closed

existing record doesn't save! #31

redvex opened this issue Oct 6, 2012 · 3 comments

Comments

@redvex
Copy link

redvex commented Oct 6, 2012

I've a simple model with "title" and "text" attribute

var chapter = Models.Chapter.findOneById(_id);

chapter.title = "title 1";
chapter.text = "text 1";

when i do

chapter.save();

nothing happens to db.

This is the log of my model:

[INFO] {
"_data" = {
id = 1;
position = 1;
"project_id" = 1;
text = "";
title = "Primo capitolo";
};
"_options" = {
table = {
all = "<KrollCallback: 0xb573120>";
count = "<KrollCallback: 0xb575df0>";
deleteRecords = "<KrollCallback: 0xb55ea10>";
exists = "<KrollCallback: 0xb56c5c0>";
findBy = "<KrollCallback: 0xb563e40>";
findById = "<KrollCallback: 0xb55d610>";
findOneBy = "<KrollCallback: 0xb56cd00>";
findOneById = "<KrollCallback: 0xb56e910>";
getColumns = "<KrollCallback: 0xb563d70>";
newRecord = "<KrollCallback: 0xb568d60>";
options = {
columns = {
id = "INTEGER PRIMARY KEY AUTOINCREMENT";
position = INTEGER;
"project_id" = INTEGER;
text = TEXT;
title = TEXT;
};
objectMethods = {
getThumb = "<KrollCallback: 0xb552d50>";
};
table = chapter;
};
save = "<KrollCallback: 0xb56b070>";
table = chapter;
truncate = "<KrollCallback: 0xb56f1a0>";
};
};
"_originalData" = {
id = 1;
};
destroy = "<KrollCallback: 0xb56bbf0>";
fromArray = "<KrollCallback: 0xb571540>";
get = "<KrollCallback: 0xb5761c0>";
getThumb = "<KrollCallback: 0xb5691f0>";
id = 1;
isChanged = "<KrollCallback: 0xb56a9a0>";
isNew = "<KrollCallback: 0xb56c9f0>";
position = 1;
"project_id" = 1;
save = "<KrollCallback: 0xb5634d0>";
set = "<KrollCallback: 0xb576df0>";
text = "Prova 1 2 3";
title = "Primo capitolo";
toArray = "<KrollCallback: 0xb54b0b0>";
}

@redvex
Copy link
Author

redvex commented Oct 6, 2012

Additional notes:

var chapter = Models.Chapter.findOneById(_cid);
Ti.API.info(chapter.title);
[INFO] First chapter
chapter.title = "title modified 1"
Ti.API.info(chapter.title);
[INFO] title modified 1
chapter.save();
Ti.API.info(chapter.title);
[INFO] First chapter

so… why?

@redvex
Copy link
Author

redvex commented Oct 7, 2012

And this is the update query:

[INFO] update chapter set id = 1, project_id = 1, title = 'First chapter', text = NULL, position = 1 where id = "1"

So the problem should be the assignment, not the save process itself

@redvex redvex closed this as completed Oct 7, 2012
@rlustemberg
Copy link

You should use the setters to update the model, not direct assigning.

chapter.fromArray({title: 'title 1' , chapter:'chapter 1'});
chapter.save()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants