Michael,

Thanks for that hint!
However, I still don't know how should I include association table
'homologues' relation :-(

I sketched a schema of my DB: http://flickr.com/photos/piotrbyzia/3244490067/
and relevant code is under: http://pastie.org/376811

The similar problem is with Interactions table - how should I define
many-to-many relation there?

SQLA seems pretty mature, but to be honest, I struggle to find one
complete example to use as a boiler plate...

Best,
Piotrek Byzia

On Feb 1, 7:02 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> remove the "secondary" argument from proteins_seed to PDB, the  
> "homologues" table has no relevance to that relation().
>
> On Feb 1, 2009, at 1:56 PM, Piotrek Byzia wrote:
>
>
>
> > My fault, I haven't included Proteins_putative, PDB is just another
> > table..
> > But anyway, the problem is with definition of many-to-many relaction()
> > in Protein_seed.
>
> > class Protein_putative(Base):
> >    __tablename__ = 'Proteins_putative'
>
> >    id = Column(Integer, primary_key=True)
> >    name = Column(String, nullable=False, unique=True)
> >    primary_accession_number = Column(String, nullable=False)
> >    description = Column(String)
> >    sequence = Column(String, nullable=False)
> >    length = Column(Integer, nullable=False)
> >    alignment = Column(String, nullable=False)
>
> >    def __init__(self, name, primary_accession_number, description,
> > sequence, length, alignment):
> >        self.name = name
> >        self.primary_accession_number = primary_accession_number
> >        self.description = description
> >        self.sequence = sequence
> >        self.length = length
> >        self.alignment = alignment
>
> >    def __repr__(self):
> >        return "<Protein_putative('%s', '%s')>" % (self.name,
> > self.primary_accession_number)
>
> > On Feb 1, 6:18 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> >> you're using homologues to link Protein_seed to PDB.   so the two
> >> foreign keys should be between the tables named "Proteins_seed" and
> >> "PDB", not "Proteins_putative", which seems to be otherwise
> >> unmentioned here.
>
> >> On Feb 1, 2009, at 11:57 AM, Piotrek Byzia wrote:
>
> >>> Hi,
>
> >>> I'm a fresh user of SQLA, and this is my first attempt to use it.
>
> >>> Based on the official tutorial example I created a many to many
> >>> relation between two tables, but I have some issues with getting it
> >>> working. It returns error "Could not determine join condition  
> >>> between
> >>> parent/child tables on relation Protein_seed.pdb_entry.  Specify a
> >>> 'primaryjoin' expression.  If this is a many-to-many relation,
> >>> 'secondaryjoin' is needed as well." I don't know how to define
> >>> secondary key, while my association table "homologues" is not
> >>> declarative and doesn't have it's own primary key. Can anybody help,
> >>> please?
>
> >>> meta = MetaData()
> >>> Base = declarative_base(metadata=meta)
>
> >>> homologues = Table('Homologues', meta,
> >>>    Column('protein_seed_id', Integer, ForeignKey
> >>> ('Proteins_seed.id')),
> >>>        Column('protein_putative_id', Integer, ForeignKey
> >>> ('Proteins_putative.id'))
> >>> )
>
> >>> class PDB(Base):
> >>>    __tablename__ = 'PDB'
>
> >>>    id = Column(Integer, primary_key=True)
> >>>    name = Column(String, nullable=False, unique=True)
> >>>    chain = Column(String, nullable=False)
>
> >>>    def __init__(self, name, chain):
> >>>        self.name = name
> >>>        self.chain = chain
>
> >>>    def __repr__(self):
> >>>        return "<PDB('%s', '%s')>" % (self.name, self.chain)
>
> >>> class Protein_seed(Base):
> >>>    __tablename__ = 'Proteins_seed'
>
> >>>    id = Column(Integer, primary_key=True)
> >>>    name = Column(String, nullable=False)
> >>>    sequence = Column(String, nullable=False)
> >>>    length = Column(Integer, nullable=False)
> >>>    alignment = Column(String, nullable=False)
> >>>    pdb_id = Column(Integer, ForeignKey('PDB.id'))
>
> >>>    # many-to-one Protein_seed * 1 PDB
> >>>    pdb_entry = relation('PDB', secondary=homologues, backref=backref
> >>> ('Proteins_seed'),
> >>>        primaryjoin=pdb_id == PDB.id)
>
> >>>    def __init__(self, name, sequence, length, alignment):
> >>>        self.name = name
> >>>        self.sequence = sequence
> >>>        self.length = length
> >>>        self.alignment = alignment
>
> >>>    def __repr__(self):
> >>>       return "<Protein_seed('%s', '%s', '%s', '%s')>" % (self.name,
> >>> self.sequence, self.length, self.alignment)
--~--~---------~--~----~------------~-------~--~----~
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