On Nov 23, 2011, at 5:20 AM, Enrico Morelli wrote: > On Wed, 23 Nov 2011 10:59:03 +0100 > Enrico Morelli <more...@cerm.unifi.it> wrote: > > >> These are the mappers: >> mapper(Ligand, ligand_table, >> properties={ >> 'ligand':relationship(LigandLigand, >> primaryjoin=and_(ligand_table.c.id==ligand_ligand_table.c.ligand_id1, >> ligand_table.c.id==ligand_ligand_table.c.ligand_id2), >> backref=backref('ligandligand') ), }) >> >> mapper(LigandLigand, ligand_ligand_table, >> properties={ >> 'first_sphere': relationship(Ligand, >> >> primaryjoin=and_(ligand_ligand_table.c.ligand_id2==ligand_table.c.id, >> >> ligand_ligand_table.c.ligand_id1==ligand_table.c.id), >> backref=backref('root')), >> }) >> >> When I try to access to the ligand.ligand properties, this is empty >> even if in the db there are relations. Where is the problem? >> >> Thanks >> >> > > I think to have solved the problem changing the logical operator in the > primaryjoin from and_ to or_. > > Now when I remove the relations I have the following warning: > SAWarning: Multiple rows returned with uselist=False for lazily-loaded > attribute > LigandLigand.ligandligand' value = callable_(passive=passive)
it means a relationship is expecting many-to-one or one-to-one and getting more than one row back. Setting uselist=True on that backref would resolve this issue, though if you only intend for one row to come back there you might want to triple-check what SQL is being emitted. The configuration here is already outside the normal realm of a "relationship" between two tables (not a traditional foreign key to primary key) so you may have to change or forego the usage of relationship() here. If it were me I'd just use two relationships to represent "ligand1" and "ligand2". -- 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.