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?)

Thanks you very much for your response and proposed solution. Will keep you
posted.

(I was rather hoping for more people to offer guidance in this matter, but
there you have it.)

Regards

Jacques

On 15 March 2011 18:51, King Simon-NFHD78
<simon.k...@motorolasolutions.com>wrote:

> > -----Original Message-----
> > From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
> > On Behalf Of jln
> > Sent: 15 March 2011 16:37
> > To: sqlalchemy
> > Subject: [sqlalchemy] In-memory object duplication
> >
>
> [SNIP]
>
> > statuses = OneToMany('DocumentStatus', inverse='doc', cascade='all,
> > delete-orphan', order_by=['timestamp'])
> >
> > So, when I create a new DocumentStatus object, Document.statuses
> > lists
> > two of them, but not actually persisted to the database. In other
> > words, leaving my Python shell, and starting the model from scratch,
> > there actually is only one child object (corroborated by squizzing
> > the
> > database directly). Here's my DocumentStatus.create() class method:
> >
> >     @classmethod
> >     @logged_in
> >     @log_input
> >     def create(cls, doc, status, person=None, date=None):
> >         person=validate_person(person)
> >         if person:
> >             status = DocumentStatus(doc=doc, status=status,
> > person=person, date=resolve_datetime(date))
> >             if status:
> >                 doc.statuses.append(status)
> >                 doc.flush()
> >                 out = 'Document status created'
> >                 success = True
> >             else:
> >                 out = 'Document status not created'
> >                 success = False
> >         else:
> >             out = 'Person does not exist'
> >             success = False
> >         log_output(out)
> >         return success
> >
> > I simply don't know why this is happening or, as I said, how to
> > search, intelligently, for an answer.
>
> I don't know Elixir, but I assume that the "inverse='doc'" line in the
> relationship sets up an SQLAlchemy backref. If so, then setting
> status.doc (presumably done in DocumentStatus.__init__) will
> automatically populate doc.statuses at the same time.
>
> So when you do doc.statuses.append(status) a bit later on, you're adding
> it to the list a second time.
>
> Hope that helps,
>
> 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.
>
>

-- 
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.

Reply via email to