> > Lets have a Person having .address having .country having .name.
> > How would "give-me-persons-which-live-in France" be expressed in
> > SA (sorry for my SQL ignorance)?
> > e.g. all-persons-for-which person.address.country.name ==
> > 'France'

>http://www.sqlalchemy.org/docs/datamapping.myt#datamapping_selectrelations_relselectby
> Unfortunately I think if your Person has a name attribute too you
> have no alternative but to write the join out the "long" way.  (I'd
> love to find out I'm wrong though. :)

ahha. Maybe the underlying query._locate_prop() can be tweaked to 
accept hierarchical keys in some form (e.g. "a.b.c.d.e.f" ), and then 
not search but just follow the hierarchy...

e.g. 
#put in orm.query.Query 
#will search for the spec.hierarchycal key as a subkey, not just as 
root)

    def _locate_prop(self, key, start=None):
        import properties
        keys = []
        seen = util.Set()
        def search_for_prop(mapper_, fullkey):
            if mapper_ in seen:
                return None
            seen.add(mapper_)
            key = fullkey[0]
            if mapper_.props.has_key(key):
                prop = mapper_.props[key]
                if len(fullkey)==1:
                    if isinstance(prop, properties.SynonymProperty):
                        prop = mapper_.props[prop.name]
                    if isinstance(prop, properties.PropertyLoader):
                        keys.insert(0, prop.key)
                    return prop
                else:
                    props = [prop]
                    fullkey = fullkey[1:]
            for prop in mapper_.props.values():
                if not isinstance(prop, properties.PropertyLoader):
                    continue
                x = search_for_prop(prop.mapper, fullkey)
                if x:
                    keys.insert(0, prop.key)
                    return x

            return None
        p = search_for_prop(start or self.mapper, key.split('.') )
        if p is None:
            raise exceptions.InvalidRequestError("Cant locate property 
named '%s'" % key)
        return [keys, p]


......
person = Person()
person.address = Address()
person.address.country = Country()
person.address.country.name = 'france'
session.save(person)
q1 = session.query(D).select_by( name='france')
q2 = session.query(D).select_by( **{'country.name':'france'} )
q3 = session.query(D).select_by( **{'address.country.name':'france'} )
assert q1 == q2 == q3
...

do try it, it seems to work...


have fun
svil

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

Reply via email to