Thank you Gaetan,

This was very helpful.  I saw that the primary/secondaryjoin arguments could
be callable, but I didn't connect that with the approach that you used in
the example.  Also thank you for clarifying the remote and local_side
arguments.

Best,
Stephen.


On Wed, Oct 29, 2008 at 12:23 PM, Gaetan de Menten <[EMAIL PROTECTED]>wrote:

> On Wed, Oct 29, 2008 at 3:23 PM, Gaetan de Menten <[EMAIL PROTECTED]>
> wrote:
> > On Wed, Oct 29, 2008 at 1:22 AM, Stephen Soltesz
> > <[EMAIL PROTECTED]> wrote:
> >> Hello, I'm experiencing an issue nearly identical in structure as that
> in a
> >> recent post:
> >>
> >>
> http://groups.google.com/group/sqlelixir/browse_thread/thread/ed8d0650b79ce942
> >>
> >> The raw sqlalchemy version works without exception.  But, my preference
> is
> >> to simply use Elixir to do this, yet I find that I'm pulling my hair out
> >> trying to figure it out.
> >> I am using Elixir - 0.6.1 and SA 0.5.0rc1.
> >>
> >> I've attached a simple test case that creates the tables in a postgres
> db.
> >>
> >> Can anyone provide a hint for what the correct translation is into
> Elixir
> >> from the code in the attached example?
> >>
> >> For the Elixir version, is there a way to reference the ClauseElements
> in
> >> the primaryjoin= & secondaryjoin= values in the same way as I do in the
> SA
> >> version?
> >>
> >> As is, the Elixir version raises:
> >>     sqlalchemy.exc.ArgumentError: Could not determine join condition
> between
> >> parent/child tables on relation UsrGrp.users.  Specify a 'primaryjoin'
> >> expression.  If this is a many-to-many relation, 'secondaryjoin' is
> needed
> >> as well.
> >>
> >> Thank you very much for any hints you can provide.
> >> Stephen.
> >
> > Well, the short answer is: this is not currently possible, due to
> > several reasons. A longer answer will follow after I have researched
> > if I can fix this easily or not.
>
> Strike that. There is an undocumented feature of SA 0.5 (not sure
> exactly when it was introduced since it's not documented) which makes
> it work/possible even with Elixir 0.6.1... See below for details...
>
> First, the problem:
> - SA usually computes the primaryjoin and secondaryjoin clauses
> automatically in most cases, and Elixir does it in addition for
> self-referencial relationships which SA doesn't handle automatically.
> This is done by introspecting the ForeignKey constraint defined on the
> tables. Since your tables don't have any, you have to define all this
> stuff manually. It seems like you figured that much.
> - Those conditions need to be expressed as
> column_object==another_column_obect, which means you need access to
> the columns of your tables. The problem is that when using Elixir and
> not explicit tables, those column object do not exist at the time of
> class definition. The solution I choose to use for Elixir, is to allow
> those arguments to be passed as callables which are then evaluated
> when the table has been loaded or created. There is one more problem:
> how do you access the columns of your intermediary table since you
> have neither an explicit table object, nor an Entity for it. There are
> two solutions here: either, you use an ugly Elixir-only hack
> (commented in the attached code), or you use an "hybrid" approach,
> that is you autoload the ManyToMany intermediary table explicitly, and
> use that table object in the ManyToMany relationship (instead of the
> name of that table). The later approach is much cleaner IMO.
> - I thought your precise use case was impossible, because in 0.6.1,
> Elixir didn't translate/call the foreign_keys argument if it is a
> callable and you need to specify it (because you don't have any in
> your table). But the good surprise of the day is that SA0.5 also
> accepts a callable for that argument, even if it is not documented.
>
> See attached script for a working example.
>
> PS:
> - even in your SA-only example, the foreign_keys argument you pass is
> wrong: it should only contain 2 columns...
> - you don't need to specify local_side and remote_side. This was only
> needed for self-referencial relationships (even if the doc doesn't
> mention it). And it should only be needed if you don't specify manual
> primary_join or secondary_join. I've just fixed these two issues (the
> doc issue and this one) in trunk.
>
> Hope it helps,
> --
> Gaƫtan de Menten
> http://openhex.org
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to