David L. <[email protected]> wrote:

> Hi,
> 
> I have a problem that is essentially identical to this:
> https://groups.google.com/forum/#!searchin/sqlalchemy/association$20table$20duplicate/sqlalchemy/2myGWqEg8LY/lCBB5q4F0PIJ
> 
> However, I'm not sure how to proceed. I understand that I can simply check
> to see if a child exists before adding it in order to avoid an
> IntegrityError. However, I still want the link between parent and child to
> be created in the association table:

you want to check that the child exists, *in that collection*. So load the
collection, if child not present, then add. This is why the linked message
recommended using collection_class=set() as one way of handling this
uniqueness on the Python side.

> 4 else if child exists: 5 retrieve extant child 6 append child to parent’s
> list of children (via association table)
> 
> Since this is handled automatically by SQLAlchemy, I have no idea how to
> go about doing step #6. The relationship is defined using a backref.

I’m not sure what the issue is with #6, you’d say
parent.collection.append(child) the same way as in #3. Nothing changes.

> MySQL is Percona 5.6.22-71.0. SQLAlchemy version is 0.9.8.
> 
> Any help would be greatly appreciated.
> 
> Thanks, David
> 
> -- 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
> [email protected]. To post to this group, send email
> to [email protected]. Visit this group at
> http://groups.google.com/group/sqlalchemy. For more options, visit
> https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to