On Oct 2, 9:45 am, "Gaetan de Menten" <[EMAIL PROTECTED]> wrote:
> On Wed, Oct 1, 2008 at 11:01 PM, esvist <[EMAIL PROTECTED]> wrote:
>
> > Is this what you ment?
>
> > from sqlalchemy import *
> > from sqlalchemy.orm import *
>
> > db = create_engine('CONNECT STRING HERE')
> > db.echo = True
>
> > meta = MetaData()
> > meta.bind = db
>
> > user = Table('USER_', meta, autoload=True)
> > case = Table('CASE', meta, autoload=True)
> > case2user = Table('CASE2USER', meta, autoload=True)
>
> > class Case(object):
> >    pass
> > class User(object):
> >    pass
>
> > mapper(Case, case, properties={
> >    'users':relation(User, secondary=case2user)
> >    })
>
> > mapper(User, user)
>
> > Here
>
> > Case.users.select()
>
> > gives me the same exception
>
> > <class 'sqlalchemy.exc.ArgumentError'>: Could not determine join
> > condition between parent/child tables on relation Case.users.  Specify
> > a 'primaryjoin' expression.  If this is a many-to-many relation,
> > 'secondaryjoin' is needed as well.
>
> > , but I'm not sure if the sample is equivalent and correct...
>
> Yes, this is what I meant. It would help if you provided a way to
> create those tables, so that the test case can be run as-is. It seems
> correct to me, except the last line:
>
> > Case.users.select()
>
> seem incorrect (though that might be a new usage of SA I'm not aware
> of). In any case, it certainly not the equivalent of
> "User.query.all()"
>
> The correct equivalent would be:
>
> session = sessionmaker()()
> session.query(User).all()
>
> The last step is to create a ticket on SA's trac with your script attached.
>
> --
> Gaëtan de Mentenhttp://openhex.org

I changed the query statement - same result...

Before posting a ticket, could you verify, this would run on any other
database (not Oracle) correctly?

Thanks for your help

The complete test case is:

CREATE TABLE user_ (
    id NUMBER(16)
    CONSTRAINT pk_user PRIMARY KEY,
    name VARCHAR2(32) NOT NULL
);

CREATE TABLE case (
    id NUMBER(16)
    CONSTRAINT pk_case PRIMARY KEY,
    name VARCHAR2(32) NOT NULL
);

CREATE TABLE case2user (
    case_id NUMBER(16) NOT NULL
    CONSTRAINT fk_c2u_case REFERENCES case (id),
    user_id NUMBER(16) NOT NULL
    CONSTRAINT fk_c2u_user REFERENCES user_ (id),

    CONSTRAINT pk_case2user PRIMARY KEY (case_id, user_id)
);



from sqlalchemy import *
from sqlalchemy.orm import *

db = create_engine('oracle://sf:[EMAIL PROTECTED]/xe')
db.echo = True

meta = MetaData()
meta.bind = db

user = Table('USER_', meta, autoload=True)
case = Table('CASE', meta, autoload=True)
case2user = Table('CASE2USER', meta, autoload=True)

class Case(object):
    pass
class User(object):
    pass


mapper(User, user)

mapper(Case, case, properties={
    'users':relation(User, secondary=case2user)
    })

session = sessionmaker()()

session.query(Case).all()

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