Actions
Bug #909
closedbool(dbo::ptr) may cause load from db
Start date:
07/19/2011
Due date:
% Done:
0%
Estimated time:
Description
Hello,
operator bool(ptr) does not need load object from db, at least when id of object is known (so object is to be persisted object).
To make sure, that operator bool can cause loading, apply this patch to tutorial2.C
diff --git a/examples/feature/dbo/tutorial2.C b/examples/feature/dbo/tutorial2.C
index 41796a9..6b987b5 100644
--- a/examples/feature/dbo/tutorial2.C
+++ b/examples/feature/dbo/tutorial2.C
@@ -109,12 +109,12 @@ void run()
transaction.commit();
}
- dbo::ptr<Post> post;
{
dbo::Transaction transaction(session);
dbo::ptr<User> joe = session.find<User>().where("name = ?").bind("Joe");
+ dbo::ptr<Post> post;
post = session.add(new Post());
post.modify()->user = joe;
@@ -130,6 +130,7 @@ void run()
dbo::ptr<Tag> cooking = session.add(new Tag());
cooking.modify()->name = "Cooking";
+ dbo::ptr<Post> post = session.load<Post>(1);
post.modify()->tags.insert(cooking);
// will print '1 post(s) tagged with Cooking.'
@@ -138,6 +139,14 @@ void run()
transaction.commit();
}
+ {
+ dbo::Transaction transaction(session);
+ dbo::ptr<Post> post = session.load<Post>(1);
+ if (post->user)
+ std::cerr << "user" << std::endl;
+ transaction.commit();
+ }
+
}
int main(int argc, char **argv)
Look at the end of output:
begin transaction
select "version", "user_id" from "post" where "id" = ?
select "version", "name", "password", "role", "karma" from "user" where "id" = ?
user
commit transaction
Updated by Koen Deforche over 13 years ago
- Status changed from New to InProgress
- Assignee set to Koen Deforche
- Target version set to 3.1.11
Updated by Koen Deforche over 13 years ago
- Status changed from InProgress to Resolved
Updated by Koen Deforche about 13 years ago
- Status changed from Resolved to Closed
Resolved in Wt 3.1.11
Actions