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...
Thanks for your help
On Oct 1, 9:23 am, "Gaetan de Menten" <[EMAIL PROTECTED]> wrote:
> On Tue, Sep 30, 2008 at 11:38 PM, esvist <[EMAIL PROTECTED]> wrote:
>
> > Spent several hours reading available documentation and searching
> > samples, but no result...
>
> > Having schema (Oracle):
>
> > 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)
> > );
>
> > and mapping it as:
>
> > class User(Entity):
> > using_options(
> > tablename='USER_',
> > autoload=True
> > )
> > cases = ManyToMany(
> > 'Case',
> > tablename='CASE2USER',
> > remote_side='case_id',
> > local_side='user_id'
> > )
>
> > class Case(Entity):
> > using_options(
> > tablename='CASE',
> > autoload=True
> > )
> > users = ManyToMany(
> > 'User',
> > tablename='CASE2USER',
> > remote_side='user_id',
> > local_side='case_id'
> > )
>
> > setup_all() passes ok
>
> > but
>
> > User.query.all()
>
> > results in
>
> > <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.
>
> > According to Elixir API documentation primaryjoin and secondaryjoin
> > should be determined automatically in this case. Any idea where I'm
> > wrong?
>
> You are not wrong anywhere I think. This code works fine here on
> another DB. This is probably a bug somewhere due to the strange casing
> used by Oracle. My guess is that it's a problem somewhere in SA, since
> on non self-referential ManyToMany relationships, Elixir doesn't
> generate any join conditions because SA can (usually) detect them
> automatically in that case.
>
> The next step would be to try to produce an SA-only test case, and if
> the problem is present there too, add a ticket on SA's trac. If you
> have any trouble producing the SA test-case, don't hesitate to ask for
> help. Can't test it myself though since I don't have access to an
> Oracle DB at the moment.
>
> --
> Gaëtan de Mentenhttp://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
-~----------~----~----~----~------~----~------~--~---