On Feb 9, 2011, at 4:34 AM, Enrico Morelli wrote:

> Dear all,
> 
> I've to create an association object where the many-to-many relation has
> to be created with only one table:
> 
> atominfo_table = Table('atom_info', metadata,
>    Column('id', types.Integer, primary_key=True),
>    Column('number', types.Integer, nullable=False),
>    Column('coord_x', types.Unicode(15), nullable=False),
>    Column('coord_y', types.Unicode(15), nullable=False),
>    Column('coord_z', types.Unicode(15), nullable=False),
>    Column('residue_id', types.Integer,
> ForeignKey('residue_info.id'),primary_key=True), 
>    Column('periodic_id', types.Integer,ForeignKey('periodic_glos.id'),
> primary_key=True), )
> 
> atom_atom_table = Table('atom_atom', metadata,
>    Column('atom1_id', types.Integer,
> ForeignKey('atom_info.id'),primary_key=True), 
>    Column('atom2_id', types.Integer, ForeignKey('atom_info.id'),
> primary_key=True), 
>    Column('interaction_type', types.Unicode(50),nullable=False), 
>    Column('distance', types.Unicode(10),nullable=False), )
> 
> Is it possible? If yes how can create the mapper?
> The following attempt give me the error:
> Could not determine join condition between parent/child tables on
> relationship AtomInfo.atom1.  Specify a 'primaryjoin' expression.  If
> 'secondary' is present, 'secondaryjoin' is needed as well.
> 
> mapper(AtomInfo, atominfo_table,
>       properties={
>          'residue': relationship(ResidueInfo, backref='atominfo'),
>          'periodic': relationship(Periodic, backref='atominfo'),
>          'atom1': relationship(AtomAtom)
>        })
> 
> mapper(AtomAtom, atom_atom_table,
>       properties={
>           'atom2': relationship(AtomInfo)
>        })

Ideally you'd be using ForeignKeyConstraint to specify a composite foreign key. 
 Otherwise it looks like theres multiple foreign keys between them, that's why 
it doesn't know how to join.

http://www.sqlalchemy.org/docs/core/schema.html#defining-foreign-keys




> 
> 
> Thanks
> -- 
> -------------------------------------------------------------------
>       (o_
> (o_    //\  Coltivate Linux che tanto Windows si pianta da solo.
> (/)_   V_/_
> +------------------------------------------------------------------+
> |     ENRICO MORELLI         |  email: more...@cerm.unifi.it       |
> | *     *       *       *    |  phone: +39 055 4574269             |
> |  University of Florence    |  fax  : +39 055 4574253             |
> |  CERM - via Sacconi, 6 -  50019 Sesto Fiorentino (FI) - ITALY    |
> +------------------------------------------------------------------+
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@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 sqlalchemy@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