I'm trying to use the object association pattern from the doco. Is it
the case that this requires departure from Declarative mode and is it
wrong to mix with non-declarative? I looked at the example code
optimized_al.py but it didn't seem to be exactly what I want. I want a
symmetric relation for adjacency of nodes in an undirected graph with
cycles. ie. it is not a tree.
<code>
class Node(DeclarativeBase):
    __tablename__ = 'node'
    #with some columns id etc.

adj = Table(u'adj', metadata,
    Column(u'node', Integer(), ForeignKey('node.id'),
primary_key=True),
    Column(u'adj_node', Integer(), ForeignKey('node.id'),
primary_key=True),
    Column(u'somedata_id', Integer(), ForeignKey('somedata.id')),
)
class Adj(object):
    __table__ = _adj
    #relation definitions
    node = relation('node')  # self-referential, bidirectional, many-
to-many
    somedata = relation('SomeData')

    def __init__(self, n1, n2):
        self.n1 = n1
        self.n2 = n2

mapper(Adj, adj, properties={
    'node': relation(Adj,
                       primaryjoin = Node.id==Adj.node,
                       #secondaryjoin = Node.id==Adj.adj_node?,
                       backref=backref('adj_node',
remoteside=[_adj.c.node])
                     )
                             }, non_primary=True)
</code>

I put the non_primary and the primaryjoin in after error messages told
me to but now this is causing another error 'Adj' has not attribute
'node' I even tried primaryjoin = Node.id==adj.c.node but then I got
"Could not locate any equated, locally mapped column pairs." This
seems to be getting a bit more  complicated than it should be already.
Is there an example of an association object in Declarative style?
Also, is it possible to do it with forward references only?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to