On Apr 26, 2006, at 6:09 AM, Gambit wrote:
One way to write the query would be to use a proper Clause
construct. You can
see an example of this in the Basic Data Mapping section at:
http://www.sqlalchemy.org/docs/index.myt?
paged=no#datamapping_relations_lazyload_relselectby
and also at:
http://www.sqlalchemy.org/docs/index.myt?
paged=no#datamapping_selecting
For your case, I imagine it might look like something as simple as:
myInstance = model.Instance.mapper.select_by(
instance.c.name == 'primary_email',
instance_type.c.name == 'email')
Hope that helps!
That helps quite a bit. thank you for all your patience. I promise
to write a 'SQLalchemy for Dummies' wiki page once I get this all
done. I think i've hit every pitfall that someone could meet in a
conversion from hand-sql to orm. i think one of the issues i'm
experiencing is that all of the examples are geared towards a
one2many or many2many relationship. there isn't really a one2one
relationship in the docs. (i'll be glad to add it once i figure this
out)
the closest thing to a one2one is in a comound mapping, which has this
preferences = relation(UserPrefs.mapper, lazy=False, private=True),
I'm accessing SQLalchemy through TurboGears and have started to use
echo to see how sqlalchemy contructs arguments , so i can try and
understand it better.
I know know that the bulk of my issues seem to be in the mapper itself
InstanceType.mapper = mapper( InstanceType , instance_type )
Instance.mapper = mapper( Instance , instance ,
properties = {
'type' : relation( InstanceType.mapper ) ,
}
)
based on that, sqlalchemy generates this sql
====
SELECT
instance.instance_type_id AS instance_instance_type_id,
instance.id AS instance_id,
instance.name AS instance_name
FROM
instance, instance_type
WHERE
instance.name = %(instance_name)s
AND
instance_type.name = %(instance_type_name)s
[engine]: {'instance_type_name': 'email', 'instance_name':
'primary_email'}
====
if i run that sql on the db itself, i get a row that looks right
through sqlalchemy though, i don't get anything
i think thats from 1 of 2 possible issues:
a - the mapper isn't processing the result set right based on my
declaration
b - the mapper is getting an invalid result set based on my
declaration.
i'm thinking this is way incorrect, because i'd expect there to be a
join on this select (as there's a FK involved and this is a one2one)
(unless sqlalchemy does the join internally, but that would be kind
of crazy)
I know i must be overthinking/overcomplicating this somewhere.
| - - - - - - - - - - - - - - - - - - - -
| RoadSound.com / Indie-Rock.net
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - -
-------------------------------------------------------
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
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users