Thank you Bobby!! That does make things more easier, and it shows then that I am being a -real- moron here..
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker, mapper, relation
meta = MetaData()
meta.bind = 'postgres://
root:sxt...@192.168.2.198/compass_master'
engine = create_engine('postgres://
root:mypas...@192.168.2.198/compass_master', echo=True)
Session = sessionmaker(bind=engine)
session = Session()
trip_table = Table('trip', meta, autoload=True)
class Trip(object):
id = Column(Integer, primary_key=True)
trip = mapper(Trip, trip_table)
trip_pc_table = Table('trip_parent_child', meta, autoload=True)
class TripParentChild(object):
parent_id = Column(Integer, ForeignKey('Trip.id'), nullable=False)
parent = relation(Trip)
child_id = Column(Integer, ForeignKey('Trip.id'), nullable=False)
child = relation(Trip)
trip_pc = mapper(TripParentChild, trip_pc_table)
Trip.children = relation(Trip, secondary = trip_table, primaryjoin = TripParentChild.parent_id == Trip.id, secondaryjoin=TripParentChild.child_id == Trip.id)
Trip.parent = relation(Trip, secondary = trip_table, primaryjoin = TripParentChild.child_id == Trip.id, secondaryjoin=TripParentChild.parent_id == Trip.id)
s = session.query(Trip).get(194143)
print s.children
results in a very nice stack trace;
Traceback (most recent call last):
File "./s.py", line 37, in <module>
print s.children
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/properties.py", line 628, in __str__
return str(self.parent.class_.__name__) + "." + self.key
AttributeError: 'RelationProperty' object has no attribute 'parent'
Any thoughts ? I suspect some attempt at 'black magic' in regards to the parent_id
Regards
Stef