On 4/6/07, George Sakkis <[EMAIL PROTECTED]> wrote:
>
> I'm using SA (with Elixir on top) and I have a parent Entity "Ranker"
> that has many children "Results"; that is, for a Ranker instance rk,
> rk.results gives its children and for a Result rs, rs.ranker gives its
> parent. When I add new children by providing the parent to the
> constructor of the child (rather than appending the child to
> rk.results) and then try to flush, I get:
>
> "FlushError: instance <Result at (...)> is an unsaved, pending
> instance and is an orphan
> (is not attached to any parent 'Ranker' instance via that classes'
> 'results' attribute)"
>
> Here's a (very) stripped-down version of what I'm doing:
>
> ranker = Ranker(...)
> for score in scores:
>     Result(ranker=ranker, score=score, **kwds).save()
> session.flush()

You shouldn't use .save() on your result instances because Elixir
automatically adds new instances of your mapped classes to the
thread's session. Or more precisely, Elixir uses the assign_mapper
plugin which in turns uses the SessionContextExt mapper extension
which does that.

And session.flush() looks suspicious too. In Elixir, you usually
either flush all pending objects using objectstore.flush() or single
instances using instance.flush()

> I expected that I can create a parent-child link either from parent to
> child (by appending to ranker.results) or from child to parent (as
> above), but apparently the latter doesn't seem to work. Is this the
> case or something else is wrong ?
>
> George


-- 
Gaƫtan de Menten
http://openhex.org

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to