In testcase above this works too:

session = Session()
user = session.query(User).filter_by(username='sector119').one()
session.close()

session = Session()
report = session.query(Report).get(1)
comment = Comment(content=u'test comment', user=user)
report.comments.append(comment)
session.add(report)
session.flush()
session.commit()
session.close()




2011-11-09 13:43:28 EET LOG:  statement: BEGIN
2011-11-09 13:43:28 EET LOG:  statement: INSERT INTO users (username) 
VALUES ('sector119') RETURNING users.id
2011-11-09 13:43:28 EET LOG:  statement: COMMIT
2011-11-09 13:43:28 EET LOG:  statement: BEGIN
2011-11-09 13:43:28 EET LOG:  statement: SELECT users.id AS users_id, 
users.username AS users_username
        FROM users
        WHERE users.username = 'sector119'
2011-11-09 13:43:28 EET LOG:  statement: INSERT INTO report (content, 
user_id) VALUES ('test report', 1) RETURNING report.id
2011-11-09 13:43:28 EET LOG:  statement: COMMIT
2011-11-09 13:43:28 EET LOG:  statement: BEGIN
2011-11-09 13:43:28 EET LOG:  statement: SELECT users.id AS users_id, 
users.username AS users_username
        FROM users
        WHERE users.username = 'sector119'
2011-11-09 13:43:28 EET LOG:  statement: ROLLBACK
2011-11-09 13:43:28 EET LOG:  statement: BEGIN
2011-11-09 13:43:28 EET LOG:  statement: SELECT report.id AS report_id, 
report.content AS report_content, report.comments_count AS 
report_comments_count, report.user_id AS report_user_id
        FROM report
        WHERE report.id = 1
2011-11-09 13:43:28 EET LOG:  statement: SELECT comment.id AS comment_id, 
comment.content AS comment_content, comment.report_id AS comment_report_id, 
comment.user_id AS comment_user_id
        FROM comment
        WHERE 1 = comment.report_id ORDER BY comment.id
2011-11-09 13:43:28 EET LOG:  statement: INSERT INTO comment (content, 
report_id, user_id) VALUES ('test comment', 1, 1) RETURNING comment.id
2011-11-09 13:43:28 EET LOG:  statement: COMMIT

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/cORJHpjqz2wJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to