On Jan 18, 2011, at 9:42 AM, Erkan Özgür Yılmaz wrote:

> Hi everybody,
> 
> (fast start :) )
> I have a class hierarchy and I'm using joined table inheritance, but my 
> classes are not always going to be used with SQLAlchemy (or I plan to give 
> the freedom to people to use these classes anywhere they want). 
> 
> Anyway I was using the "entity_type" column in my base table to map the 
> polymorphic_identity. It was nice to have the "entity_type" variable *after* 
> mapping with SQLAlchemy. Now, I decided to add this variable to all my 
> classes as a new class variable. So my problem is when I map with SQLAlchemy 
> the variable becomes an sqlalchemy.orm.attributes.InstrumentedAttribute and 
> prints out None before committing the objects, so I created another column 
> for the discriminator with the name "db_entity_type" now I'm not able to use 
> the default value for "entity_type" from the class. Is there a solution for 
> that?

0.7 has the polymorphic discriminator column auto-populated when you first 
create an object, so you wouldn't have this issue then.   

For now keep your db_entity_type as the mapped column, keep entity_type as 
class based, and use it in the mapping:

class MyClass(MyParent):
   entity_type = 'myclass'

mapper(MyClass, mytable, inherits=MyParent, 
polymorphic_identity=MyClass.entity_type)



> 
> Thanks...
> 
> E.Ozgur Yilmaz
> Lead Technical Director
> eoyilmaz.blogspot.com
> www.ozgurfx.com
> 
> -- 
> 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.

-- 
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