See attachment. Tested against 0.3.6.


Michael Bayer napsal(a):
> 
> On Apr 12, 2007, at 12:53 PM, ml wrote:
> 
>> I tried s.query(Address).select_by(user=u) as I found similar in the
>> documentation
>> (http://www.sqlalchemy.org/docs/ 
>> datamapping.html#datamapping_selectrelations_relselectby)
>> but SA raises:
>> AttributeError: 'LazyLoader' object has no attribute 'columns'
>>
> 
> 
> works for me, cant reproduce.  please attach a full reproducing test  
> case.
> 
> > 
> 

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

#!/usr/bin/python2.4
# -*- coding: utf-8 -*-

from sqlalchemy3 import *
import datetime, pickle, sys

engine = create_engine("sqlite://", echo=True)

metadata = BoundMetaData(engine)

users_table = Table("users", metadata, 
    Column("id", Integer, primary_key=True),
    Column("user_name", String(16))
)

addresses_table = Table("addresses", metadata,
    Column("id", Integer, primary_key=True),
    Column("id_user", Integer, ForeignKey("users.id")),
    Column("addr", String(100))
)

class User(object):
    def __init__(self, user_name):
        self.user_name = user_name

class Address(object):
    def __init__(self, addr):
        self.addr = addr

mapper(Address, addresses_table)
mapper(User, users_table, properties = {
        "addresses" : relation(Address, cascade="all, delete-orphan", 
                               backref=backref("user")),
    }
  )

metadata.create_all(engine)

s = create_session(bind_to=engine)

u1 = User("bob")
a1 = Address("bob's house")
a2 = Address("bob's flat")
u1.addresses.append(a1)
u1.addresses.append(a2)
s.save(u1)

u2 = User("alice")
a3 = Address("alice's house")
a4 = Address("alice's flat")
u2.addresses.append(a3)
u2.addresses.append(a4)
s.save(u2)

s.flush()

u = s.query(User).get_by_user_name("bob")
for i in s.query(Address).select_by(user=u):
    print i.addr

Reply via email to