Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
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

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Bayer
On Feb 14, 2014, at 12:46 PM, Michael Hipp mich...@redmule.com wrote: 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

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 11:50 AM, Michael Bayer wrote: On Feb 14, 2014, at 12:46 PM, Michael Hipp mich...@redmule.com wrote: 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_,

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Bayer
right this is why reading the docs is better, those have been checked… remote side for m2o refers to the primary key, so: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Animal(Base):

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 1:51 PM, Michael Bayer wrote: right this is why reading the docs is better, those have been checked... remote side for m2o refers to the primary key, so: The docs says: '...directive is added known as remote_side, which is a Column or collection of Column objects that indicate

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Bayer
On Feb 14, 2014, at 3:16 PM, Michael Hipp mich...@redmule.com wrote: On 2/14/2014 1:51 PM, Michael Bayer wrote: right this is why reading the docs is better, those have been checked... remote side for m2o refers to the primary key, so: The docs says: '...directive is added known as

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 2:34 PM, Michael Bayer wrote: A basic fact of a self referential relationship is that you're building a tree. The root of the tree has to be NULL and I'd advise against trying to work around that. Now if you wanted to in fact assign the object's own primary key to the foreign

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Bayer
On Feb 14, 2014, at 4:29 PM, Michael Hipp mich...@redmule.com wrote: On 2/14/2014 2:34 PM, Michael Bayer wrote: A basic fact of a self referential relationship is that you're building a tree. The root of the tree has to be NULL and I'd advise against trying to work around that. Now

Re: [sqlalchemy] Parent child relationships

2014-02-14 Thread Michael Hipp
On 2/14/2014 3:36 PM, Michael Bayer wrote: the django ORM would write an autogenerated primary key value to a foreign key column at the same time in a single INSERT? What magic might they have discovered there? (hint: i am sure they don't do that) Naw. If you recall I was supplying the pkey

[sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
I'm trying to do something like this: 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',

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Bayer
On Feb 13, 2014, at 11:53 AM, Michael Hipp mich...@redmule.com wrote: I'm trying to do something like this: class Animal(Base): __tablename__ = 'animals' id_ = Column(Integer, primary_key=True) sire_id = Column(Integer, ForeignKey('animals.id_')) dam_id = Column(Integer,

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:06 AM, Josh Kuhn wrote: I think you need to use the remote_side argument for the children relationship, since it's the same table http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#adjacency-list-relationships Thanks. I'm just not sure how to specify it when there

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:04 AM, Michael Bayer wrote: On Feb 13, 2014, at 11:53 AM, Michael Hipp mich...@redmule.com wrote: I don't see a first_owner relationship defined above, so the above example is not complete. The approach using foreign_keys is the correct approach to resolving ambiguity in join

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Josh Kuhn
I think you need to use the remote_side argument for the children relationship, since it's the same table http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#adjacency-list-relationships On Thu, Feb 13, 2014 at 12:04 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Feb 13,

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Bayer
On Feb 13, 2014, at 12:16 PM, Michael Hipp mich...@redmule.com wrote: On 2/13/2014 11:04 AM, Michael Bayer wrote: On Feb 13, 2014, at 11:53 AM, Michael Hipp mich...@redmule.com wrote: I don't see a first_owner relationship defined above, so the above example is not complete. The approach

Re: [sqlalchemy] Parent child relationships

2014-02-13 Thread Michael Hipp
On 2/13/2014 11:45 AM, Michael Bayer wrote: primaryjoin=and_(Animal.sire_id == Animal.id_, Animal.dam_id == Animal.id) Thank you. That works great. And thanks for the explanation. Michael -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To