Hi guys, I've got a question regarding the association object pattern. Though perhaps it's not what I should be using...
Let's say I've got a Parent class that I'd like to add tags with data to. class Parent(Base) id = Str # The association object class Tag(Base) parent_id = Str child_id = Int value = Float # The child object, comes with some data too class Child(Base) id = Int name = Str date = Date The relation setup is just like in the example in the docs. So now I'd like to create a set of tags and pass the info the tag needs to create its child to its constructor. tags = [Tag(name='name1', date=dt.date.today()), ...etc. ] Then do something like: parent = Parent() for tag in tags: parent.tags.append(tag) # can I use a set here instead of a list? The bit that I'm struggeling with is duplicate tag objects... In the tag's constructor I have: child = sess.query(Child).filter(Child.name == name).filter(Child.date == date).first() if child is None: child = Child(name=name, date=date) self.child = child So if there's a child object in the db with the same name and date it uses that as it's child field. Though I'm getting : raise exc.FlushError("New instance %s with identity key %s conflicts with persistent instance %s" % (state_str(state), str(instance_key), state_str(existing))) Which means the tag I'm adding is allready in the db. Which is true. Normally I'd use merge to get around that, but don't know how to do that since I'm 'adding' the new instance through parent.tags.append() Any ideas how to solve this? Am I simply using the wrong approach? Regards, Christian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---