Hey Jonathan,

I think I'd need to see a little more of your code to really see what you're
doing, but here's a recommendation anyways (though probably not as specific as
you hope for :).  On the wiki in the Usage Recipes section I've tossed up
several working examples to demonstrate a couple different issues.  Whenever I
get a problem like this, I use that existing basic setup, alter it to
demonstrate the behavior in question, and try to get it to work.  That way,
when something (as below) doesn't behave as I think it does, I can include a
working test case, verbose output log, AND plain English in the email to the
list.

It's a lot more useful for everyone involved PLUS these testcases often get
placed into the unittest framework.  More unittests is a good thing :)

So if you could do something similar, it might help us figure out where things
have gone astray.

Regardless, it looks to me like you haven't set up your foreign key
relationships properly.  I suspect this because while the sample SQL you
pasted shows your criteria (which I assume is something similar to the select_by
query from previously) it doesn't show the relationship between the tables at
all (i.e. a 'instance.instance_type_id == instance_type.id' clause).

Good luck!
-G

On Wednesday, April 26, 2006, 9:13:25 PM, you wrote:
> 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



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

Reply via email to