I'm using SQLAlchemy's declarative mode with polymorphic
relationships, so I have a base Node class along with several child
classes (ListNode, FileNode, etc.)  A polymorphic_identity in the Node
table determines the class of object being loaded (node_type = 'list',
'file', etc.). Each child class has its own attributes (stored in the
class' own table) as well as the base class attributes (stored in the
Node table). I'm sure this is pretty basic stuff, but it's all working
nicely, thanks to help
I've received here and elsewhere.

Now I'd like to implement a RESTful interface that allows me to create
new Node items of the various child classes.  The inbound parameters
to the REST call would include the common Node attributes -- including
node_type, the polymorphic identity -- as well as child class-specific
attributes.  I need to create an object of the appropriate class, pass
the parameters to the new object for validation, and store it.

Loading an object works nicely with the polymorphism that's set up --
I just query for the object and SQLAlchemy gives me one of the proper
class.  However, I'm unclear how to *create* an object
polymorphically, given the information I have.  I could, of course,
create an independent mapping of node_type to child classes, use the
REST call's inbound node_type to create an object of the appropriate
class, etc. A duplicate map seems redundant, though; it seems that
there should be a proper way to do this using SQLAlchemy's own
facilities, but I haven't been able to figure out how.

Is there a direct way through SQLAlchemy to create an object of the
proper class, using its polymorphism features?  If not,
is there a way to get to its own identity-to-class map so at least I
wouldn't have to maintain a separate one?

Thanks in advance for any help!




--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en.


Reply via email to