why dont you specify the "foreignkey" argument ? just point it to
one of the columns involved in the join which represents the "other"
side of the relation (assuming the ActiveMapper lets all those
arguments come in...). as usual, more specific answers come with
full examples :) .
On Mar 14, 2006, at 7:32 AM, Qvx 3000 wrote:
I'm trying to establish a "relation" between two tables which have
no PK/FK relation in reality. There is a LOG_EVENTS table with
events comming from all arount the system. I can extract usefull
log entries by the use of NDC (nested diagnostic context) which is
really just a tag attached to number of log events. Table JOBS has
a column LOG_NDC_ID which has the same tag. I'm trying to use those
two columns to establish a relationship but I'm getting:
=========
sqlalchemy\mapping\properties.py in _find_dependent(self)
261 self.primaryjoin.accept_visitor(visitor)
262 if dependent[0] is None:
--> 263 raise ArgumentError("cant determine primary
foreign key in the join relationship....specify foreignkey=<column>
or foreignkey=[<columns>]")
264 else:
265 self.foreigntable = dependent[0]
ArgumentError: cant determine primary foreign key in the join
relationship....specify foreignkey=<column> or foreignkey=[<columns>]
Here is my attempt:
=========
class Job(ActiveMapper):
class mapping:
__table__ = 'jobs'
id = column(Integer, primary_key = True)
...
description = column(Unicode(250), default=None)
#log_events = one_to_many("LogEvent") # Gave up on this one
class LogEvent(ActiveMapper):
class mapping:
__table__ = 'log_events'
sort = column(Integer, primary_key = True) # not realy a
primary key, used on rare occassions for sorting
...
ndc_id = column(Integer) # Nested Diagnostic Context
message = column(Unicode(4000))
Job.mapper.add_property("log_events",
relation(LogEvent.mapper, primaryjoin=
LogEvent.c.ndc_id==Job.c.log_ndc_id, lazy=True))
Additionally, I was later hoping to extract the messages using
LIMIT/OFFSET, but also have no idea how.
If it can't work like this, I guess I'm just going to make plain
Python property or utility method.
Thanks,
Tvrtko
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users