On Sep 26, 2009, at 1:25 PM, BEES INC wrote:

> class Vals(dict): pass
>
> class Foo(object):
>
>       def __init__(self, name):
>               self.vals = Vals()
>               self.name = name
>
>       def add(self, key, value):
>               self.vals[key] = value

you would need to say self.vals[key] = Vals() here.    
column_mapped_collection uses full ORM instances as values.   In any  
case I don't think you mean to map the "vals" table to a "dict"  
subclass - the mapping of a table to a class implies how to represent  
a single *row*, not the full table as a whole.

If you are attempting to map from scalar keys to scalar (non object)  
values, you should look into using the AssociationProxy to accomplish  
that.




>
> engine = create_engine('sqlite:///:memory:', echo=True)
> meta = MetaData(bind=engine)
> Session = sessionmaker(bind=engine)
>
> vals = Table('vals', meta,
>       Column('id', Integer, primary_key=True),
>       Column('date', DateTime),
>       Column('val', Integer),
>       Column('foo_id', Integer, ForeignKey('foo.id'))
> )
>
> mapper(Vals, vals)
>
> foo = Table('foo', meta,
>       Column('id', Integer, primary_key=True),
>       Column('name', String(50))
> )
>
> mapper(Foo, foo, properties = dict(
>       vals = relation(Vals, collection_class = column_mapped_collection
> (vals.c.date))
> ))
>
> sess = Session()
> meta.create_all()
>
> f = Foo('hello')
> f.add(datetime.now(), 1.0)
>
>
> >


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