Thanks for pointing me in the right direction Michael.

On Sep 4, 7:34 am, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
> mgemmill wrote:
>
> > What would be the recommended method of mapping something like a Money
> > class - objects that are a basic value + descriptor where the
> > descriptor (in this example currency) is more than just a primitive
> > variable?
>
> > For example:
>
> > class Currency(object):
> >    def __init__(self, code, descrip):
> >            self.code = code
> >            self.descrip = descrip
>
> > class Money(object):
> >    def __init__(self, value, currency):
> >            self.value = value
> >            self.currency = currency
>
> > class Product(object):
> >    def __init__(self, code, cost):
> >            self.code = code
> >            self.cost = cost
>
> > My first thought was to apply a composite mapping to the Product
> > table.  If a money value was simply Money(10.00,'EUR') it is
> > straightforword. However, I want the full use of a Currency object
> > ( i.e. Money(10.00,Currency('EUR')) ). I also don't want to map a
> > separate table (a many-to-many relation) just to record monetary
> > values for a Product object. Is it possible to apply a foreign key
> > within a composite mapping?
>
> its not a composite and also since the "10.00" would be a local column,
> its not a related object either.  for this you'd hand-roll a descriptor
> (i.e. using Python's "property" function) of your own that
> receives/returns the Money() value object as requested.  Money() itself is
> not known by the ORM.   You can also make your own descriptor class (i.e.
> an object with __get__(), __set__(), __del__()) that can be reused to
> apply attributes of this type to any class.
--~--~---------~--~----~------------~-------~--~----~
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