patrick wrote:
> Hi,
>   I'm trying to use the secondary argument to create a relation that
> joins two tables through an intermediary.  SQLAlchemy says that it
> can't figure out the correlation automatically.  There are other
> relations and mappings going on here on these tables, but the base of
> this is as follows.  Relations don't have any "correlate" keyword like
> queries.  Any input?
>
> class Sequence(BaseStruct, Base):
>     __tablename__ = 'sequence'
>     __table_args__ = (
>             {'autoload':True}
>             )
>
> class FamilySequence(BaseStruct, Base):
>     __tablename__ = 'family_sequence'
>     __table_args__ = (
>             ForeignKeyConstraint(['sequence_key'],
> ['protein.sequence_key']),
>             ForeignKeyConstraint(['family_key'], ['family.id']),
>             {'autoload':True}
>             )
>     sequence =
> relation(Sequence,primaryjoin="FamilySequence.sequence_key==Sequence.id",lazy=True)
>
> class Family(BaseStruct, Base):
>     __tablename__ = 'family'
>     __table_args__ = (
>             {'autoload':True}
>             )
>     proteins =
> relation(Protein,secondary=FamilySequence.__table__,primaryjoin="Family.id==FamilySequence.family_key",secondaryjoin="FamilySequence.sequence_key==Protein.sequence_key",lazy=True,uselist=True,backref="families")
>
> InvalidRequestError: Select statement 'SELECT
> count(family_sequence.sequence_key) AS count_1 FROM family_sequence,
> family WHERE family.id = family_sequence.family_key' returned no FROM
> clauses due to auto-correlation; specify correlate() to control
> correlation manually.

that error message is referring to a query that is also using count(),
which is something that is not illustrated in your mappings nor is your
usage of count() shown here.  There's nothing obviously wrong with the
mappings themselves as illustrated above, the issue lies with how you are
forming a count() query.

For these kinds of issues its best to pass along a small test case that
fully reproduces the behavior you are seeing.



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

Reply via email to