Here is what I did first

    q = session.query(Spec.SpecID,Spec.Spec_Name,
            Rqmt.RqmtID,Rqmt.Rqmt_Name,
            Rparam.RparamID,Rparam.Rparam_Name,
            Rvalue.RvalueID,Rvalue.Rvalue_Name).\
            join(Rqmt,Rparam,Rvalue)

SA complains about more than one foreign key constraint as expected

Then I tried many variations of
    q = session.query(Spec.SpecID,Spec.Spec_Name,
            Rqmt.RqmtID,Rqmt.Rqmt_Name,
            Rparam.RparamID,Rparam.Rparam_Name,
            Rvalue.RvalueID,Rvalue.Rvalue_Name).\
            join(Rqmt,Rparam, (Rvalue, ????????????))

I want to be able to use the class attributes that define the relation
Rvalue to Rqmt and Rvalue to Rparam, but don't know what use in place of the
?????????????.
If I put a tuple in for the ???
      (Rvalue,(Rqmt.Rvalue,Rparam.Rvalue))  I get an error

 File
"C:\Python25\lib\site-packages\sqlalchemy-0.5.2-py2.5.egg\sqlalchemy\sql\expression.py",
line 2579, in _from_objects
self.left._from_objects + \
AttributeError: 'tuple' object has no attribute '_from_objects'

If I separate the join into 2 pieces,
      (Rvalue, Rqmt.Rvalue),(Rvalue, Rparam.Rvalue)
I get a cross join and bad results.

The only correct solution I have is to use a SQL expression
    (Rvalue, and_(Rparam.RparamID==Rvalue.Rvalue_RparamID,
              Rqmt.RqmtID==Rvalue.Rvalue_RqmtID))

If possible, I want to take advantage of the class mapped attributes for the
relations somewhat like the query.join() documentation describes. The
problem is how to express a single join when it depends on 2 foreign keys to
2 different targets.

Am I missing something, or do I always have to use a SQL expression in this
case?

-- 
Mike Conley



On Thu, May 7, 2009 at 1:34 PM, Michael Bayer <mike...@zzzcomputing.com>wrote:

>
> Mike Conley wrote:
> >
> > Question:
> > Can I express the join to table Rvalue in terms of the relation
> attributes
> > defined on the classes instead of needing a SQL construct that
> essentially
> > is restating the foreign key relationships? The documentation for
> > query.join() has some examples using relation attributes, but I can't
> > figure
> > out the syntax when 2 foreign keys are present.
> >
> >
> http://www.sqlalchemy.org/docs/05/reference/orm/query.html?highlight=#sqlalchemy.orm.query.Query.join
> >
>
> the syntax is the same regardless of how many foreign keys are present.
> whatever the primaryjoin condition of the relation() is, is what will be
> expressed.
>
> >
>

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