if you change the bottom to this:
ret = m.select(and_(
users.c.user_id == mails.c.user_id ,
mails.c.mail_address.like('%a%')
))
for R in ret:
print R.user_name
for a in R.mail:
print a.mail_address
and you get this result:
Sam
[EMAIL PROTECTED]
Ted
[EMAIL PROTECTED]
[EMAIL PROTECTED]
which is correct. Its every user who has an email address with an
"a" in it. then list out each user, and all their email addresses.
But I have a feeling that youre thinking it will give you just the
email address with the "a" in it on each user, eh ? well, thats not
how it works. eager loading is just related to loading the full set
of properties for an object, in exactly the same manner as a lazy
loader does except in one SQL pass; it is not a query tool for your
primary class.
if you want just some of their email addresses, thats another query:
l = class_mapper(Mail).select(mails.c.mail_address.like('%a%'))
for a in l:
user = class_mapper(User).get(a.user_id)
print user.user_name, a.mail_address
giving you:
Sam [EMAIL PROTECTED]
Ted [EMAIL PROTECTED]
On May 9, 2006, at 2:48 PM, Sandro Dentella wrote:
Hi,
the attached script produces a sql statement that I can't correctly
interpret but anyhow gives wrong results (doubled rows):
m.select(users.c.user_id == mails.c.user_id, from_obj=[users])
SELECT user_tbl.user_last_name AS user_tbl_user_last_name,
mail_tbl_3b11.user_id AS mail_tbl_3b11_user_id,
mail_tbl_3b11.mail_address
AS mail_tbl_3b11_mail_address, user_tbl.user_id AS
user_tbl_user_id,
user_tbl.user_name AS user_tbl_user_name
FROM mail_tbl, user_tbl LEFT OUTER JOIN mail_tbl AS mail_tbl_3b11
ON user_tbl.user_id = mail_tbl_3b11.user_id
WHERE user_tbl.user_id = mail_tbl.user_id
All the examples in the documentation have a neater statement
(FROM table1
LEFT JOIN table2).
Adding another condition as in
m.select(and_(
users.c.user_id == mails.c.user_id ,
mails.c.mail_address.like('%a%')
)
from_obj=[users])
just fails (no LIKE whereclause applied)
Is this an SA bug or I'm doing something wrong with the select?
TIA
sandro
PS: should I use from_obj? I never see a difference if I use the join
condition...
--
Sandro Dentella *:-)
e-mail: [EMAIL PROTECTED]
http://www.tksql.org TkSQL Home page - My GPL work
<sqlite-mail.py>
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users