you need to add the assocaition table, "rule_path" as the second
argument to the Path.mapper relation(), i.e.
Rule.mapper = mapper(Rule, rule_info, properties=dict(
paths = relation(Path.mapper, rule_path,
primaryjoin=and_(rule_info.c.tkn_name==rule_path.c.tkn_name,
...
hard to spot for sure, I had to run this to figure it out, so I added
an assertion to check for that condition...it will raise ValueError
if theres a secondaryjoin but no secondary argument.
Also, this example is raising the fact that I havent yet built
ForeignKey to support multiple columns, which would make this easier.
Why is the "path_info" table all primary key columns ? what
information does it store ?
On Feb 10, 2006, at 8:21 PM, Karl Guertin wrote:
So I'm trying to do a many to many mapping using the following schema:
path_info = Table('path_info', engine,
Column('tkn_name', String(64),primary_key=True),
Column('fcn_name', String(64),primary_key=True),
Column('path_id', Integer,primary_key=True))
rule_info = Table('rule_info', engine,
Column('id', Integer),
Column('tkn_name', String(64),primary_key=True),
Column('fcn_name', String(64),primary_key=True),
Column('name', String(64),primary_key=True))
rule_path = Table('rule_path', engine,
Column('tkn_name', String(64)),
Column('fcn_name', String(64)),
Column('rule_name', String(64)),
Column('path_id', Integer))
Path.mapper = mapper(Path, path_info)
Rule.mapper = mapper(Rule, rule_info, properties=dict(
paths = relation(Path.mapper,
primaryjoin=and_(rule_info.c.tkn_name==rule_path.c.tkn_name,
rule_info.c.fcn_name==rule_path.c.fcn_name,
rule_info.c.name==rule_path.c.rule_name),
secondaryjoin=and_(rule_path.c.tkn_name==path_info.c.tkn_name,
rule_path.c.fcn_name==path_info.c.tkn_name,
rule_path.c.path_id==path_info.c.path_id))
))
I'm having trouble figuring out how to do the above mapping. It's
basically the same as an integer many to many mapping but I'm not sure
how to indicate the foreign keys. I get a 'Cant determine the
direction' error from the above (or a no syncrules generated or an
assertion error depending on how I move around the declarations, I'm
not sure on primary vs secondary, etc). What am I doing wrong?
I know the query that I want and I would think the above would
generate something like:
SELECT *
FROM path_info
LEFT JOIN rule_path ON
path_info.fcn_name=rule_path.fcn_name AND
path_info.tkn_name = rule_path.tkn_name AND
path_info.path_id=rule_path.path_id
LEFT JOIN rule_info ON
rule_path.fcn_name=rule_info.fcn_name AND
rule_path.tkn_name=rule_info.tkn_name AND
rule_path.rule_name=rule_info.name
WHERE
rule_info.fcn_name=':fcn_name' AND
rule_info.tkn_name=':tkn_name' AND
rule_info.name=':rule_name';
But with path_info's fields listed out rather than just a *.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through
log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD
SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users