Hi all,
i'm stil trying to understand the whole thing, be patient please...
below I report a complete sqlite example that I don't really
understand. It's mapper with 2 relations:
m = mapper(User, users, properties = { 'addr': rel, 'cities' : rel2 } )
what I don't understand is that property 'addr' and 'cities' appear to be
different to my understanding. An example is the fact that 'addr' property
is 'sizable' and has a count() method), while 'cities' do not.
Why is this this way?
I arrived here while trying to get a print of all sql-rows as if I used the
join from the command line. Is there a standard solution when you don't know
in advance which are the properties? (I'm writing a tool that should "edit
a mapper result" getting all used info from the result and the mapper).
Thanks in advance
sandro
*:-)
--
Sandro Dentella *:-)
e-mail: [EMAIL PROTECTED]
http://www.tksql.org TkSQL Home page - My GPL workplease
from sqlalchemy import *
import sys, re, datetime
sys.path.append ('../../../')
import py_path, config, reflect, mask
import sd
sd.dbg = 1
from sqlalchemy import *
from layout import *
from validator import Validator
eng = create_engine("sqlite://", echo=False)
cities = Table('city', eng,
Column('city', String(30), primary_key = True),
Column('country', String(30), nullable = False)
)
users = Table('users', eng,
Column('user_id', Integer, primary_key = True),
Column('user_name', String(30), nullable = False),
Column('city', String(30), ForeignKey("city.city"), nullable = False),
Column('user_last_name', String(30), nullable = False))
users.create()
users.insert().execute(
{'user_name': 'Sam', 'user_last_name': 'Patts', 'city' : 'Milan' },
{'user_name': 'Sid', 'user_last_name': 'Watts', 'city' : 'Rome' },
{'user_name': 'Axe', 'user_last_name': 'Smith', 'city' : 'Paris' },
{'user_name': 'Ted', 'user_last_name': 'Will' , 'city' : 'Madrid' })
mails = Table('mails', eng,
Column('mail_address', String(30), nullable = True,
primary_key = True),
Column('user_id', Integer, ForeignKey("users.user_id")))
mails.create()
mails.insert().execute(
{'mail_address': '[EMAIL PROTECTED]', 'user_id': 1},
{'mail_address': '[EMAIL PROTECTED]', 'user_id': 2},
{'mail_address': '[EMAIL PROTECTED]', 'user_id': 4},
{'mail_address': '[EMAIL PROTECTED]', 'user_id': 4})
cities.create()
cities.insert().execute(
{'city': 'Rome', 'country': 'Italy'},
{'city': 'Milan', 'country': 'Italy'},
{'city': 'Paris', 'country': 'Paris'},
{'city': 'Madrid', 'country': 'Madrid'}
)
class User(object): pass
class Mail(object): pass
class City(object): pass
m2 = mapper(Mail, mails)
rel = relation(m2)
c2 = mapper(City, cities)
rel2 = relation(c2)
m = mapper(User, users, properties = { 'addr': rel, 'cities' : rel2 } )
ret = m.select()
print ret[0].addr, len(ret[0].addr)
print ret[0].cities, len(ret[0].cities)