Hi all,
I'm trying to set up a many-to-many system using the Declarative syntax
against an existing MySQL set of tables. We're using a 'link' table
between two other tables we want to relate many-to-many. Here's the
simplified layout of those tables:
mysql> desc press_routing_press;
+------------------+----------------------+------+-----+---------+------
-+
| Field | Type | Null | Key | Default | Extra
|
+------------------+----------------------+------+-----+---------+------
-+
| press_routing_id | int(10) unsigned | NO | MUL | |
|
| press_id | int(10) unsigned | NO | MUL | |
|
| type | enum('new','rework') | YES | | NULL |
|
+------------------+----------------------+------+-----+---------+------
-+
mysql> desc press;
+-------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+-------+
| id | int(10) unsigned | NO | PRI | | |
| code | varchar(15) | YES | | NULL | |
| name | varchar(25) | YES | | NULL | |
+-------------+------------------+------+-----+---------+-------+
mysql> desc press_routing;
+--------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| id | int(10) unsigned | NO | PRI | | |
| code | varchar(20) | NO | | | |
| press | int(10) unsigned | NO | | | |
+--------------+------------------+------+-----+---------+-------+
And here's the Python SqlAlchemy code I've put together trying to
describe this:
class PressRoutingPress(Base):
'''This class defines the many-to-many join table between press
and press_routing.
'''
__tablename__ = "press_routing_press"
__table_args__ = {'autoload' : True}
press_id = Column(Integer, ForeignKey('press.id'), primary_key=True)
press_routing_id = Column(Integer, ForeignKey('press_routing.id'),
primary_key=True)
class PressRouting(Base):
'''This class defines the press_routing table information.
'''
__tablename__ = "press_routing"
__table_args__ = {'autoload' : True}
class Press(Base):
'''This class defines the press table information.
'''
__tablename__ = "press"
__table_args__ = {'autoload' : True}
# many to many Press<->PressRouting
press_routing = relation('PressRouting',
secondary=PressRoutingPress,
primaryjoin=id==PressRoutingPress.press_id,
foreign_keys=[PressRoutingPress.press_id],
secondaryjoin=PressRouting.id==PressRoutingPress.press_routing_id,
foreign_keys=[PressRoutingPress.press_routing_id],
uselist=False)
#backref=backref('press'))
#viewonly=True)
This all works till I try to instantiate an instance of a Press()
object, then I get the following exception:
sqlalchemy.exc.ArgumentError: Could not determine relation direction for
primaryjoin condition 'press_routing_press.press_id = %s', on relation
Press.press_routing. Are the columns in 'foreign_keys' present within
the given join condition ?
I've tinkered around with various things in the relation() defined in
the Press class, but that just seems to generate other exceptions. From
what I've read the above code looks closest to something that should
work based on what I've seen others posting.
Any help and/or guidance would be appreciated, thanks!
Doug
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---