I'm not too sure what the proper db vocab is to describe my problem
but I will illustrate in code. I would like to do something like the
below:
---------------------------------------------------------
class VehicleBuilder(Entity):
""" person who builds vehicles """
name = Field(Unicode(60))
#vehicle_type = ??? # <-- this is what I want to know how to
do
class Vehicle(Entity):
using_options(inheritance='multi', polymorphic='vehicle_type')
class Car(Vehicle):
pass
class Van(Vehicle):
pass
class SUV(Vehicle):
pass
---------------------------------------------------------
I would like to specify that every VehicleBuilder only builds a
certain type of vehicle (e.g. 'Car').
>>> bob = VehicleBuilder(name='Bob', vehicle_type=Car)
I can picture the db organization of this, and I would imagine that in
the python mapping it should return the class of Car. Even if it
returned the string of the class I could work with that.
Is this possible? I've looked through the Elixir faq and docs as well
as through SQLAlchemy, but didn't see anything *quite* like this (but
I could've missed it).
I haven't thought it out completely, but I was also thinking something
that might work would be to define the 'VehicleType' table/class
manually, and add a ManyToOne column to the 'Vehicle' class, but I
think this would create a redundant column.
-----------------------------------------------------
class VehicleType(Entity):
name = FieldUnicode(15)
class Vehicle(Entity):
using_options(inheritance='multi') # not specifying 'polymorphic'
vehicle_type = ManyToOne('VehicleType')
class Car(Vehicle):
def __init__(self):
self.vehicle_type = 'Car'
class Van(Vehicle):
pass
---------------------------------------------------
Any help would be appreciated. Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---