thanks Michael,

because I edited my question a couple of times, and also trying to solve it
while editing the text, it went to a slightly different way then I want to
point to,

Let me explain it in a different way, may be I am asking the wrong question:

Right now I'm developing an Open Source Production Asset Management System
(ProdAM). Lets say I have Project, Sequence, Shot, Asset, Task etc. classes,
each class should have a status attribute:

A Project can have these statuses:
    - Waiting To Start
    - On Hold
    - In Progress
    - Complete

A Shot can have these statuses:
    - Waiting To Start
    - Waiting Offline
    - In Progress
    - On Hold
    - Pending Review
    - Approved
    - Complete

A Sequence can have these statuses:
    - Waiting To Start
    - On Hold
    - In Progress
    - Pending Review
    - Approved
    - Complete

etc.

As you see most of the statuses are going to be common, so I decided to have
a StatusList object holding Status objects. And let the user create all the
statuses he needs in his studio and then group them in StatusList objects.

But this introduces another problem, when the user creates a new Project
object he needs to specify which StatusList he wants to use, and serving all
the StatusLists and letting him to choose is not a good idea (then he can
choose a wrong StatusList which is not designed for that kind of objects).

So instead of doing that, and to automate this part, I wanted to have
another object holding the available StatusList objects for specific object
types, lets say an EntityTypeStatusListOption table/object which has a
column for "entity_type" and another for "statusList_id". (all right we are
there finally). Then, I wanted to use the entity_type attribute of the
polymorphic_identity (just because it was showing the type of the object)
and the id of the StatusList to hold the StatusList for specific kind of
objects.

And because I'm using plain Python objects in my class hierarchy, I didn't
want to use something (the "entity_type" attribute) which is only introduced
when the user uses SQLAlchemy (after mapping). Then, I decided to add the
"entity_type" as a class attribute and try to persist it and also use it as
the polymorphic_identity, but it didn't work like that, I did what you
suggest (another column with the name "db_entity_type" for the
polymorphic_identity) but then I couldn't able to store the value of the
class attribute "entity_type" in the base table (where as the db_entity_type
was holding the correct value (db_entity_type=MyClass.entity_type) ) I
believe I need to store it to be able to use it in secondary join with the
EntityTypeStatusListOption table (or should I use the db_entity_type for the
join, may be, anyway, I'm not sure). So this is my first question, do you
have any suggestion?

My second question is about the validity of my idea, just because I have
never designed a system which uses a database, I'm not sure about all this
setup, and may be I'm making it complex than it needs to be, or there are
other simple ways of doing the same thing (I think I need to read about the
design patterns in relational databases). So anyway is there anything you
can suggest me with this setup.

and sorry about asking something which is not directly related with
SQLAlchemy itself but the design of the database.

Thank you again...

E.Ozgur Yilmaz
Lead Technical Director
eoyilmaz.blogspot.com
www.ozgurfx.com


On Tue, Jan 18, 2011 at 5:56 PM, Michael Bayer <mike...@zzzcomputing.com>wrote:

>
> 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<sqlalchemy%2bunsubscr...@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