> -----Original Message----- > From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] > On Behalf Of Jacques Naude > Sent: 17 March 2011 12:32 > To: sqlalchemy@googlegroups.com > Subject: Re: [sqlalchemy] In-memory object duplication > > Hi, Simon > > Thanks for the quick response. > > Elixir doesn't use __init__ - there's something automatic going on > there. My create(), in essence, does the job of __init__, which means > you might still be hitting the nail on the head. I haven't had the > time to test it out yet, but I will. (Why, though, would the double > entry not be persisted to the database too?) >
The entry only appears once in the database because SQAlchemy works hard to ensure that a single object instance corresponds to a single row in the database. It doesn't really make sense (in the standard one-to-many model) for a particular child to appear more than once in a parent-child relationship. By default, SA uses a list as the collection implementation for relationships, and doesn't care if you add the same instance more than once. If it bothers you, you could use a set instead: http://www.sqlalchemy.org/docs/orm/collections.html#customizing-collecti on-access Simon -- 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.