moggie wrote:
> Greetings,
>
> Hope you are well. In my example I have two objects 'HttpTest' and
> 'SmtpTest' that both inherit from their super-class called 'Test'.
>
> Due to the nature of the relationship, 'Test' will never actually be
> stored in the database so I've not mapped that. However, a mixture of
> 'HttpTest' and 'SmtpTest' objects are both to be stored in the
> hosttest_table, thus I created a mapping for them like this:
>
>   httptest_mapper = mapper(HttpTest, hosttest_table, \
>               polymorphic_on=hosttest_table.c.type,
> polymorphic_identity='http')
>   smtptest_mapper = mapper(SmtpTest, hosttest_table, \
>               polymorphic_on=hosttest_table.c.type,
> polymorphic_identity='smtp')
>
> Unfortunately when I do, I get this error message:
>
>   No such polymorphic_identity 'smtp' is defined
>
> I was hoping SQLA would understand this and let me pack the two
> objects into the same table, but for some reason it doesn't like it.
>
> If someone could please give me some pointers on how to proceed, it
> would be greatly appreciated. Thank you in advance for your time and
> consideration.

the pattern you're attempting here is called "single table inheritance".  
You will need to define a common base class between your two classes, but
it never need be instantiated directly.   Full documentation on how to use
this approach is at
http://www.sqlalchemy.org/docs/05/mappers.html#single-table-inheritance .



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

--

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