I have an interesting problem that I haven't been able to solve for quite 
some time. I keep finding information about association proxies and the 
like, but nothing that really helps (or maybe I'm implementing it 
incorrectly).

Let's start with this:

    class HandledProjectedItemList(list):
        def append(self, proj):
            proj.projected = True   
            list.append(self, proj)
    
                    
    item_table = Table("items", saveddata_meta,
        Column("ID", Integer, primary_key = True),
        Column("itemID", Integer, nullable = False, index = True),
        Column("name", String, nullable = False),
        Column("timestamp", Integer, nullable = False),
    )
    
    projectedItem_table = Table("projectedItem", saveddata_meta,
        Column("sourceID", ForeignKey("item.ID"), primary_key = True),
        Column("destID", ForeignKey("item.ID"), primary_key = True),
        Column("enabled", Integer))
        
    mapper(Item, item_table,
        properties = {"projectedItem" : relation(Item,
                        primaryjoin = projectedItem_table.c.destID == 
item_table.c.ID,
                        secondaryjoin = item_table.c.ID == 
projectedItem_table.c.sourceID,
                        secondary = projectedItem_table,
                        collection_class = HandledProjectedItemList)
                      })


I have two tables: a `item` table, and a `projectedItem` table. The `item` 
table is the main one, and contains information on items. The projected 
items table is a self-referential many-to-many relationship to the items 
table, where each item may have a collection of other items attached to it. 
We use a custom collection class to load this relationship so that we can 
modify a special attribute in the Item objects (if they are loaded via this 
relationship, they have their `projected` attribute set to `True`).

This works great. But I also want read / write access to that extra 
`enabled` column in the relationship table, while maintaining the current 
functionality of loading the projected items into this custom collection 
class. I haven't found any information on that that helps, or like I said 
before, maybe I'm just not using it correctly.

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