I apologize for this second, longer, more detailed, post, but I
thought my first response
to the request for more descriptions was incomplete...
On May 22, 3:08 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> a1.join(a2, <onclause>) should do it. if not, supply a full test case
> and a description of the specific problem.
The database tables were defined elsewhere, via
code like this:
nis_user = Table('nis_users', meta,
Column('id', Integer, primary_key = True),
Column('eid', String(32), default=""),
Column('uid', Integer, nullable = False),
Column('uname', String(256), nullable = False),
UniqueConstraint('eid', 'uid', 'uname')
)
nis_account = Table('nis_accounts', meta,
Column('id', Integer, primary_key = True),
Column('domain_id', Integer, ForeignKey('domains.id')),
Column('nis_user_id', Integer, nullable = False),
Column('gid', Integer, default=60001),
Column('gcos', String(256)),
Column('shell', String(256)),
Column('home', String(256)),
Column('terminated', Boolean, default = False),
Column('reassigned_uid', Boolean, default = False),
Column('active', Boolean, default = True),
UniqueConstraint('domain_id', 'nis_user_id'),
ForeignKeyConstraint(['nis_user_id'],['nis_users.id'],
ondelete="CASCADE")
)
So here's the Python Code:
nis_users_table = Table('nis_users', metadata, autoload=True)
nis_accounts_table = Table('nis_accounts', metadata, autoload=True)
class NisAccount(object):
pass
class NisUser(object):
pass
mapper(NisUser, nis_users_table, properties = {
'accounts':relation(NisAccount,
primaryjoin=nis_users_table.c.id ==
nis_accounts_table.c.nis_user_id,
backref='user',
lazy=False)
},
order_by = nis_users_table.c.uid
)
mapper(NisAccount, nis_accounts_table, properties={
'uid' : column_property(
select(
[nis_users_table.c.uid],
nis_users_table.c.id ==
nis_accounts_table.c.nis_user_id
).correlate(nis_accounts_table).label('uid')
),
'uname' : column_property(
select(
[nis_users_table.c.uname],
nis_users_table.c.id ==
nis_accounts_table.c.nis_user_id
).correlate(nis_accounts_table).label('uname')
),
'eid' : column_property(
select(
[nis_users_table.c.eid],
nis_users_table.c.id ==
nis_accounts_table.c.nis_user_id
).correlate(nis_accounts_table).label('eid')
)
}
)
So, when I do
s = select([nis_accounts_table, nis_users_table],
from_obj=[nis_accounts_table.join(nis_users_table)]).where(nis_users_table.
c.eid != '')
I get the SQL query I expect.
Then I do:
a1 = s.correlate(None).alias()
a2 = s.correlate(None).alias()
Now, trying to make a new select:
s2 = select(from_obj=[a1.join(a2), a1.c.eid == a2.c.eid])
Gives me a <sqlalchemy.sql.expression.Select ...> object
When I do:
print s2
I get:
Traceback (most recent call last):
File "<console>", line 1, in ?
File "/Users/jeff/src/web/uuid-tg/lib/python2.4/site-packages/
SQLAlchemy-0.4.6-py2.4.egg/sqlalchemy/sql/expression.py", line
1136,
in __str__
return unicode(self.compile()).encode('ascii',
'backslashreplace')
File "/Users/jeff/src/web/uuid-tg/lib/python2.4/site-packages/
SQLAlchemy-0.4.6-py2.4.egg/sqlalchemy/sql/expression.py", line
1132,
in compile
compiler.compile()
File "/Users/jeff/src/web/uuid-tg/lib/python2.4/site-packages/
SQLAlchemy-0.4.6-py2.4.egg/sqlalchemy/sql/compiler.py", line 181,
in
compile
self.string = self.process(self.statement)
File "/Users/jeff/src/web/uuid-tg/lib/python2.4/site-packages/
SQLAlchemy-0.4.6-py2.4.egg/sqlalchemy/sql/compiler.py", line 189,
in
process
return meth(obj, **kwargs)
File "/Users/jeff/src/web/uuid-tg/lib/python2.4/site-packages/
SQLAlchemy-0.4.6-py2.4.egg/sqlalchemy/sql/compiler.py", line 491,
in
visit_select
froms = select._get_display_froms(existingfroms)
File "/Users/jeff/src/web/uuid-tg/lib/python2.4/site-packages/
SQLAlchemy-0.4.6-py2.4.egg/sqlalchemy/sql/expression.py", line
3034,
in _get_display_froms
toremove = itertools.chain(*[f._hide_froms for f in froms])
AttributeError: '_BinaryExpression' object has no attribute
'_hide_froms'
So the question is twofold:
1. What am I doing wrong?
2. How do I see the SQL that would be generated if I'm doing nothing
wrong?
Jeff.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---