On 2014-04-05 16:58, Michael Bayer wrote:
> On Apr 5, 2014, at 8:14 AM, Christian Kastner <debian.kvr...@gmail.com> wrote:
>> I have a many-many relationship implemented as an Association Object.
>> When I add an association between a parent and a child, the list of
>> associations within the parent contains the child element twice. A
>> flush() does not help, but commit() resolves the issue. The
>> generated SQL only creates one INSERT, though (as expected).
> 
> # SIDE QUESTION: Why is the following line required for association objects?
> # With an association TABLE (following the doc's many-many example), omitting
> # this works; with an assoc OBJECT the next line (append) raises 
> IntegrityError
> a.parent = par
> par.children.append(a)
> 
> By first assigning "a.parent = par", that does not trigger any lazy load and
> Association is now fully associated with both Parent and Child. When this
> occurs, it is *already present* in "par.children", again due to backrefs

Ah, *that* was the connection I was missing. I figured that both those
lines were somehow redundant but always assumed that the second line was
the correct one, and always kept playing around with the preceding code,
and with cascades= (apparently never hitting the right option).

Makes sense to me now, many thanks!
Christian



-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to