On 2/13/2014 11:45 AM, Michael Bayer wrote:
So for "children" above you need to spell out primaryjoin completely which is primaryjoin="and_(Animal.sire_id == Animal.id_, Animal.dam_id == Animal.id)".

Thought I was on the right track but now getting the exception below. Here's the model:

class Animal(Base):
    __tablename__ = 'animals'
    id_ = Column(Integer, primary_key=True)

    sire_id = Column(Integer, ForeignKey('animals.id_'))
    dam_id = Column(Integer, ForeignKey('animals.id_'))

    sire = relationship('Animal', foreign_keys=[sire_id])
    dam = relationship('Animal', foreign_keys=[dam_id])
    pjoin = 'and_(Animal.sire_id == Animal.id_, Animal.dam_id == Animal.id_)'
    children = relationship('Animal', foreign_keys=[sire_id, dam_id],
                            primaryjoin=pjoin)

So I attempt to put in the first object, which is to be a bit special:

    unknown = Animal(id_=0)
    db_session.add(unknown)
    unknown.sire = unknown   # <- get exception here
    unknown.dam = unknown
    db_session.commit()

TypeError: Incompatible collection type: Animal is not list-like

unknown.sire shows to contain [] so it evidently wants a list of sires? That's not what I had in mind for the above model. Any help?

Thanks,
Michael

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to