On Mar 11, 2014, at 3:50 PM, Bala <[email protected]> wrote:

>     45    class Groups(ModelBase, VersionColumnMixin):
>     46        id = sa.Column('id', sa.Integer, Sequence('id_seq'), 
> primary_key=True)
>     47        domain_id = sa.Column(sa.String(36), DefaultClause('default'), 
> nullable=False)
>     48        description = sa.Column(sa.Text)
>     49        date_created = sa.Column(sa.DateTime)
>     50        group_name = sa.Column(sa.String(64), nullable=False, 
> index=True)
>     51        child_groups = relationship('Groups', 
> secondary=groups_and_groups_assoc_table,
>     52                                      
> primaryjoin=id==groups_and_groups_assoc_table.c.parent_group_id,
>     53                                      
> secondaryjoin=id==groups_and_groups_assoc_table.c.child_group_id,
>     54                                      backref='parent_groups')

here, when the definition of the Python identifier "id" within the Groups class 
definition is removed, it is no longer valid to refer to the word "id" within 
the "primaryjoin" and "secondaryjoin" conditions, as "id" is not defined.  The 
reason it seems to be defined is that it is resolving to the Python built in 
function "id".  Unfortunately the exception message isn't being too smart here, 
interpreting "id" as just another literal value like the number "3" so you 
don't see it, it wouldn't be a bad idea for SQLA to detect this kind of thing 
but that is actually somewhat difficult as it is valid for an expression to 
refer to a callable.

Since "id" is not yet defined within the class body of Groups you need to 
specify conditions using a string:

class Groups(ModelBase, VersionColumnMixin):
    domain_id = sa.Column(sa.String(36), DefaultClause('default'), 
nullable=False)
    description = sa.Column(sa.Text)
    date_created = sa.Column(sa.DateTime)
    group_name = sa.Column(sa.String(64), nullable=False, index=True)
    child_groups = relationship('Groups', 
secondary=groups_and_groups_assoc_table,
                                  
primaryjoin="Groups.id==groups_and_groups.c.parent_group_id",
                                  
secondaryjoin="Groups.id==groups_and_groups.c.child_group_id",
                                  backref='parent_groups')
    __table_args__ = (sa.UniqueConstraint('domain_id', 'group_name'),)


i'm updating the document at 
http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#self-referential-many-to-many-relationship
 to include this form now.





-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to