>From your code it's not clear how you're going to differentiate
between "matches" and "merges" - basically, you need something in your
database which makes "matches" different from "merges" and then
configure the retationships to use those fields.

See the "Boston addresses" example in the documentation:
http://docs.sqlalchemy.org/en/latest/orm/relationships.html#specifying-alternate-join-conditions

Or maybe you even need two FKs - source_id and another one, and,
again, configure the relationships to use those FKs.
http://docs.sqlalchemy.org/en/latest/orm/relationships.html#specifying-foreign-keys

On Mar 18, 7:18 pm, Devraj Mukherjee <dev...@gmail.com> wrote:
> Hi all,
>
> I am trying to created self references to a Table, I actually need two
> self references back to the same Table.
>
>     matches = relationship("Criterion")
>     merges = relationship("Criterion")
>
> What I notice happens is the references are getting mixed up. Hence
> when I add to matches it adds to the merges property.
>
> Is there a better / cleaner way of doing this?
>
> Here's what I have for now:
>
> class Criterion(Base):
>
>     __tablename__ = 'criterion'
>     criterion_id = Column(Integer, Sequence('criterion_sequence'),
> primary_key=True)
>     standard_id = Column(Integer, ForeignKey('standard.standard_id',
> ondelete="CASCADE"), nullable=False)
>     source_id = Column(Integer, ForeignKey('criterion.criterion_id'),
> nullable=True)
>
>     number = Column(Integer())
>     title = Column(Text())
>     statement = Column(Text())
>     created = Column(DateTime, default=func.current_timestamp())
>     last_updated = Column(DateTime, default=func.current_timestamp(),
> onupdate=func.current_timestamp())
>
>     matches = relationship("Criterion")
>     merges = relationship("Criterion")

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