On 6/28/06, Dennis Muhlestein <[EMAIL PROTECTED]> wrote:
I've set up a simple many-to-many relation almost exactly as the 0.2.4 docs specify for using a secondary table:
drawing=Table( Column('id', <SNIP all the columns /> )
tags=Table ( 'tags', engine,
Column ( 'id', Integer, primary_key=True,nullable=False ),
Column ( 'name', VARCHAR(20), nullable=False,index='ix_tags_name' ) )
drawing_tags = Table ( 'drawing_tags', engine,
Column ( 'drawing_id', Integer, ForeignKey(' drawings.id'),primary_key=True,nullable=False ),
Column ( 'tag_id', Integer, ForeignKey(' tags.id'), primary_key=True,nullable=False ) )
class Tag(object):
pass
class Drawing(object):
pass
mapper(Drawing,drawing,
properties={
'tags':relation(Tag,secondary=drawing_tags)
}
)
mapper(Tag,tags,properties={'drawings':relation(Drawing,secondary=drawing_tags)})
The following works:
d=s.query(Drawing).get( <whatever_id> )
d.tags
[ the, list, of, tags ]
The following also works
t=s.query(Tag).get( <whatever_id> )
t.drawings
[ the, list, of, drawings ]
The last one here doesn't quite work though:
d=s.query(Drawing).select_by( name == <whatever tag name> )
for name I've tried name, tag_name and a few others. the query can't resolve those properties. The docs were a little unclear as to whether we needed = or == for the operator so I tried both but neither worked.
The only thing that worked was to use tags.c.name == <whatever_id> but then the query is as follows:
SELECT drawings.id, <snipped columns />
FROM tags, drawings
WHERE tags.name = <whatever_name> ORDER BY drawings.id
Notice that the from clause isn't doing the join on drawing_tags. The resulting data set contains all the drawings instead of the joined drawings on the association table.
So, am I missing something here? Has a bug been introduced or am I doing something wrong.
ThanksDennis
An added Note:
if I do s.query(Drawing).select_by(name='test') I get:
File "build/bdist.linux-i686/egg/sqlalchemy/orm/query.py", line 128, in search_for_prop
File "build/bdist.linux-i686/egg/sqlalchemy/orm/query.py", line 128, in search_for_prop
File "build/bdist.linux-i686/egg/sqlalchemy/orm/query.py", line 128, in search_for_prop
File "build/bdist.linux-i686/egg/sqlalchemy/orm/query.py", line 128, in search_for_prop
File "build/bdist.linux-i686/egg/sqlalchemy/orm/query.py", line 119, in search_for_prop
File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line 166, in _get_props
RuntimeError: maximum recursion depth exceeded
Thoughts, I'm sure I've missed some dumb little detail somwhere.
-Dennis
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