Michael Bayer wrote:
> w...@nobleenergyinc.com wrote:
>> Here's the issue, boiled down to one file.  On import, the last
>> statement
>> fails, mapping the Connections object. I just need to map two relations
>> on
>> an association object (Connections) to a polymorphic union
>> (NetworkNode).
>> Is there a way to do this?
>
> your "foreign_keys" is outside of "downstreamnodes" and is being set up as
> a relationship() of its own.  corrected:


I've beefed up this particular error message to indicate it is working on
a property called "foreign_keys".


>>
>> sqlalchemy.exc.ArgumentError: Column 'network_nodes.node_id' is not
>> represented in mapper's table.  Use the `column_property()` function to
>> force this column to be mapped as a read-only attribute.
>>
>> from sqlalchemy import *
>> from sqlalchemy import sql
>> from sqlalchemy import orm
>>
>> metadata = MetaData()
>>
>> tbl1 = Table("source_sink",metadata,
>>              Column("node_id",Integer,primary_key=True),
>>              Column("source_sink_name",String(60),nullable=False),
>>              Column("source_or_sink",String(6)))
>> tbl2 = Table("meas_type_a",metadata,
>>              Column("node_id",Integer,primary_key=True),
>>              Column("meas_point_name",String(60),nullable=False),
>>              Column("subtype",String(10)),
>>              Column("latitude",Numeric(precision=12,scale=9,asdecimal=True)),
>>              
>> Column("longitude",Numeric(precision=12,scale=9,asdecimal=True)))
>> tbl3 = Table("meas_type_b",metadata,
>>              Column("node_id",Integer,primary_key=True),
>>              Column("meas_point_name",String(60),nullable=False),
>>              Column("subtype",String(10)),
>>              Column("latitude",Numeric(precision=12,scale=9,asdecimal=True)),
>>              
>> Column("longitude",Numeric(precision=12,scale=9,asdecimal=True)),
>>              Column("capacity",Numeric(precision=6,scale=2,asdecimal=True)))
>> tbl4 = Table("meas_type_c",metadata,
>>              Column("node_id",Integer,primary_key=True),
>>              Column("meas_point_name",String(60),nullable=False),
>>              Column("subtype",String(10)),
>>              Column("latitude",Numeric(precision=12,scale=9,asdecimal=True)),
>>              
>> Column("longitude",Numeric(precision=12,scale=9,asdecimal=True)),
>>              Column("stringuserfield1",String(40)),
>>              
>> Column("numericuserfield1",Numeric(precision=6,scale=2,asdecimal=True)))
>> nn = orm.util.polymorphic_union({1:tbl1,2:tbl2,3:tbl3,4:tbl4},
>>                                 "node_type","network_nodes")
>> cnct = Table("connections",metadata,
>>              Column("upstream_id",Integer,primary_key=True),
>>              Column("upstream_type",Integer,primary_key=True),
>>              Column("downstream_id",Integer,primary_key=True),
>>              Column("downstream_type",Integer,primary_key=True),
>>              Column("effective_date",DateTime(timezone=False)),
>>              Column("expiration_date",DateTime(timezone=False)))
>> class NetworkNode(object):
>>     pass
>>
>> nnmapper =
>> orm.mapper(NetworkNode,nn,primary_key=[nn.c.node_id,nn.c.node_type],
>>                       
>> with_polymorphic=('*',nn),polymorphic_on=nn.c.node_type)
>>
>> class SourceSinkNode(NetworkNode):
>>     pass
>> ss =
>> orm.mapper(SourceSinkNode,tbl1,inherits=nnmapper,polymorphic_identity=1,concrete=True)
>> class MeasTypeA(NetworkNode):
>>     pass
>> ma =
>> orm.mapper(MeasTypeA,tbl2,inherits=nnmapper,polymorphic_identity=2,concrete=True)
>> class MeasTypeB(NetworkNode):
>>     pass
>> mb =
>> orm.mapper(MeasTypeB,tbl3,inherits=nnmapper,polymorphic_identity=3,concrete=True)
>> class MeasTypeC(NetworkNode):
>>     pass
>> mc =
>> orm.mapper(MeasTypeC,tbl4,inherits=nnmapper,polymorphic_identity=4,concrete=True)
>> class Connection(NetworkNode):
>>     pass
>>
>> connmapper = orm.mapper(Connection,cnct,properties=dict(
>>                         upstreamnodes=orm.relation(NetworkNode,primaryjoin=
>>                           and_(cnct.c.downstream_id==nn.c.node_id,
>>                                cnct.c.downstream_type==nn.c.node_type),
>>                         foreign_keys=[nn.c.node_id,nn.c.node_type]),
>>                         downstreamnodes=orm.relation(NetworkNode,primaryjoin=
>>                           and_(cnct.c.upstream_id==nn.c.node_id,
>>                                cnct.c.upstream_type==nn.c.node_type)),
>>                         foreign_keys=[nn.c.node_id,nn.c.node_type]))
>>
>> Wes Dyk
>>
>> --
>> 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.
>>
>>
>
> --
> 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.
>
>

-- 
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