On Oct 28, 2007, at 11:02 PM, Ron wrote:

>
> I have a datastore that consists of 3 tables.
>  1. Thing table (just a primary-key name column)
>  2. Attr table (key/value columns with an id and foreign key to Thing
> table)
>  3. Thing-to-Thing relation table (Things can be 'connected' to each
> other)
>


heres some questions:

does the metaclass create a mapper() for every subclass ?  i.e. is  
there a mapper for Server, SunServer, etc ?  it seems like there is  
(since by "the wrong mapper" i meant, calling object_mapper(instance)  
returns a Server or SunServer mapper, not the Thing mapper which  
loaded the object).

if there is a distinct mapper per class, cant your metaclass simply  
assign a hidden "type" attribute to each class, a single string value  
which indicates what class to load ?  then you can just have a single  
"type" column in the thing table and SA's regular inheritance  
mechanisms take care of the rest.  the metaclass would only need to  
worry about things when the user first creates the object.  im not  
seeing any reasons here why this wouldnt work.

also when you say "the user shouldnt have to know about SA", that  
suggests the other way I might do this, that Thing stays as Thing and  
the user-facing object is actually a wrapper for a Thing, and is not  
mapped to the ORM directly.  this makes it less convenient as the  
user-facing object cant be used in SA operations directly, you'd have  
to translate around sessions and queries.

theres three examples in the distro you should look at:

examples/polymorph/single.py - single table inheritance
examples/vertical/vertical.py - stores "vertical" attributes  
similarly to your Thing
examples/elementtree/adjacency_list.py - this is mostly about self- 
referential relationships, but also illustrates how a non-mapped  
object can be "supplied" its internals by a mapped object (i.e. its a  
wrapper).

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to