Hi,

I've got the following tables in my app (only showing applicable
columns here) storing categories for my app:

Base
- id (int) PK
- deleted (int) - 0/1 as a value

Category
- id (int) PK/FK - refers to Base.id
- parent_id (int) FK - self-referential to Category.id

I then have a Category object, which inherits from Base. All's good.

What I'm trying to do is when I get my Category object I only get
children which aren't deleted=1. My original property in my mapper was
this:

'children': relation(Category,
                           primaryjoin=TABLES.CATEGORY.c.id==
TABLES.CATEGORY.c.parent_id,
                           backref=backref('parent',
 
remote_side=[TABLES.CATEGORY.c.id]
                                                    ),
                          ),

Which works fine but gets everything. So I changed it to this:

'children': relation(Category, secondary=TABLES.BASE,
 
primaryjoin=TABLES.CATEGORY.c.id==TABLES.CATEGORY.c.parent_id,
 
secondaryjoin=and_(TABLES.BASE.c.id==TABLES.CATEGORY.c.id,
 
TABLES.BASE.c.deleted==False),
                           foreign_keys=[TABLES.CATEGORY.c.id],
                           backref=backref('parent',
 
remote_side=[TABLES.CATEGORY.c.id]
                                                    ),
                           ),

and I get nothing. Not a single object. Is my issue:

1. Foreign key related?
2. Join related?
3. Developer related?

Any help here is appreciated.

Thanks!

Jon

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