On Nov 8, 2011, at 1:47 PM, sector119 wrote:
> Hi.
>
> Why SA produce last UPDATE if I set report_id value?
> And why it produces those two SELECTs if I do not perform read access to
> report and report.comments?
> Should not it exec only one insert?
again, no idea. the get() will emit a SELECT. The TripReportComment
constructor will do nothing, unless something else is going on that is causing
it to be flushed. The append to report.comments() will emit another SELECT.
The add() will do nothing. I'd assume theres a flush() or commit() happening
somewhere causing the second UPDATE, which would only occur if the previous
value of report_id was not 7, or was expired.
I would greatly appreciate if you could provide full, succinct examples for
these, thanks !
>
> report = session.query(TripReport).get(id)
> comment = TripReportComment(content=form.content.data, user=request.user,
> report_id=form.report_id.data)
> report.comments.append(comment)
> session.add(report)
>
>
> SELECT trip_reports.id AS trip_reports_id, trip_reports.title AS
> trip_reports_ti
> tle, trip_reports.content AS trip_reports_content, trip_reports.route AS
> trip_reports_route, trip_reports.date_start AS t
> rip_reports_date_start, trip_reports.date_end AS trip_reports_date_end,
> trip_reports.type_id AS trip_reports_type_id, tri
> p_reports.user_id AS trip_reports_user_id, trip_reports.schedule_id AS
> trip_reports_schedule_id, trip_reports.create_date
> AS trip_reports_create_date, trip_reports.comments_count AS
> trip_reports_comments_count
> FROM trip_reports
> WHERE trip_reports.id = '7'
>
> INSERT INTO trip_report_comments (content, user_id, report_id) VALUES ('test
> content', 6, '7') RETURNING trip_report_comments.id
>
> SELECT trip_report_comments.id AS trip_report_comments_id,
> trip_report_comments.
> content AS trip_report_comments_content, trip_report_comments.create_date AS
> trip_report_comments_create_date, trip_repor
> t_comments.user_id AS trip_report_comments_user_id,
> trip_report_comments.report_id AS trip_report_comments_report_id
> FROM trip_report_comments
> WHERE 7 = trip_report_comments.report_id ORDER BY
> trip_report_comments.id
>
> UPDATE trip_report_comments SET report_id=7 WHERE trip_report_comments.id = 5
>
>
> --
> 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/-/YKVkfJu5Q80J.
> 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.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
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.