add a "holding zone" for backref-appended collection items when collection hasn't lazy loaded

Issue #871 resolved
Mike Bayer repo owner created an issue

i.e.

mapper(Student, table_students, properties={
       'marks': relation(Mark, cascade='all, delete-orphan',
backref='student')
       })
mapper(Subject, table_subjects, properties={
       'marks': relation(Mark, cascade='all, delete-orphan',
backref='subject')
       })
mapper(Mark, table_marks)

[skip ...](...)

mark = Mark()
s.save(mark)
mark.student = student_1
mark.subject = subject_1
mark.value = 5
s.flush()

Here is SQL output (shortened a bit for ease of reading):

SELECT * FROM marks WHERE 1 = marks.student_id        <-----
unnecessary select
SELECT * FROM marks WHERE 1 = marks.subject_id         <-----
unnecessary select
BEGIN
INSERT INTO marks (subject_id, student_id, value) VALUES (1, 1, 5)
COMMIT

the un-lazyloaded "marks" collections should remain un-lazyloaded when the backref event appends to them; they should instead place the object in a supplemental list, similar to that of DynamicInstrumentedAttribute, which is merged with the collection when it is ultimately lazy loaded.

Comments (2)

  1. Log in to comment