I have a tree structure

Root
  |
  +--Area
  |    |
  |    +--SubArea
  |    |    |
  |    |    +--Item
  |    |    |
  |    |    +--Item
  |    |
  |    +--SubArea
  |         |
  |         +--Item
  |         |
  |         +--Item
  |
  +--Area
       |
       +--SubArea
       |    |
       |    +--Item
       |    |
       |    +--Item
       |
       +--SubArea
            |
            +--Item
            |
            +--Item

The tree structure corresponds to slqalchemy db tables `areas`,
`subareas` and `items`.

Something like this:

    mapper(Area, areas_table, properties={
        'subareas': relationship(SubArea, backref='parent'),
        })
    mapper(SubArea, subareas__table, properties={
        'items': relationship(Item, backref='parent'),
        })
    mapper(Item, items_table)

so each Area instance will have a `subareas` list and each SubArea
will have a `items` list,

also I easyly get a backref `parent` from Item to parent SubArea and
from
SubArea to parent Area.

But this won't be for Root: it will not have a `areas` list in Root
nor its areas will have a parent reference to Root.

The quick-and-dirty solution is to do this in Root:

    self.areas = query(Area).all()
    for area in self.areas:
        area.parent = self

But it won't be the same thing as sqlalchemy `relationship` attributes
so:
are there alternative solutions more sqlalchemy-like?

Any tip appreciated!

Thank you for your support

Greetings
neurino

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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