I have more stuff placed above the "virtual_*" like photogalleries,
specifications, ... So I'd like some neat layered code design - class
tripplets for all purposes (ArticlesCategory, Article, ArticleProposal),
(PhotosCategory, Photo, PhotoProposal), ...
I want to call
sess.query(Articles)...
and not
sess.quary(VirtualItem).filter(VirtualItem.kind=="article")...
My mappers are like:
class VirtualCategory(object): pass
class VirtualItem(object): pass
class VirtualProposal(object): pass
mapper(VirtualCategory, table_virtual_categories,
polymorphic_on=table_virtual_categories.c.kind,
polymorphic_identity="none"
)
mapper(VirtualItem, table_virtual_items,
polymorphic_on=table_virtual_items.c.kind,
polymorphic_identity="none"
)
mapper(VirtualProposal, table_virtual_proposals,
polymorphic_on=table_virtual_items.c.kind,
polymorphic_identity="none,
)
class ArticlesCategory(object): pass
class Article(object): pass
class ArticleProposal(object): pass
mapper(ArticlesCategory, table_articles_categories,
inherits=VirtualCategory,
polymorphic_identity="articles"
)
mapper(Article, table_articles,
inherits=VirtualItem,
polymorphic_identity="article"
)
mapper(ArticleProposal, table_article_proposals,
inherits=VirtualProposal,
polymorphic_identity="article"
)
and I'd like to eliminate the articles table in this case and make the
Article mapper like:
mapper(Article, table_virtual_items,
inherits=VirtualItem,
polymorphic_identity="article"
)
This doesn't work because it doesn't do any join and doesn't use the
discriminator column so it works with all rows in the table virtual_items.
[EMAIL PROTECTED] napsal(a):
> and you mappers look like?
> why u need to inherit articles at all then? just use the base..
>
> On Tuesday 10 June 2008 15:34:21 ml wrote:
>> Hi!
>>
>> I have following situation: I have 3 tables which stand as a base
>> for other stuff:
>>
>> table_virtual_categories = Table("virtual_categories", meta,
>> Column("id", Integer, primary_key = True),
>> Column("id_parent", Integer,
>> ForeignKey("virtual_categories.id")), Column("visible", Boolean,
>> nullable=False, default=False), Column("kind", String(10),
>> nullable=False),
>> )
>>
>> table_virtual_items = Table("virtual_items", meta,
>> Column("id", Integer, primary_key = True),
>> Column("id_category", Integer,
>> ForeignKey("virtual_categories.id"), nullable=False),
>> Column("kind", String(10), nullable=False),
>> )
>>
>> table_virtual_proposals = Table("virtual_proposals", meta,
>> Column("id", Integer, primary_key = True),
>> Column("id_previous_version", Integer,
>> ForeignKey("virtual_proposals.id")),
>> Column("id_item", Integer, ForeignKey("virtual_items.id"),
>> nullable=False),
>> Column("title", Unicode(100)),
>> Column("dt_inserted", DateTime, nullable=False,
>> default=func.now()), Column("dt_valid_from", DateTime),
>> Column("dt_valid_to", DateTime),
>> Column("version", LUnicode(100), nullable=False),
>> Column("state", Integer, nullable=False)
>> )
>>
>> Now I have some situations where I need to inherit some of these
>> tables but I want to keep the schema category-item-proposal:
>>
>> E.g. articles: I need special columns for categories and proposals
>> but articles (~items) have no extra columns:
>>
>> table_articles_categories = Table("articles_categories", meta,
>> Column("id", Integer, ForeignKey("virtual_categories"),
>> primary_key = True),
>> Column("description", UnicodeText),
>> )
>>
>> table_articles = Table("articles", meta,
>> Column("id", Integer, ForeignKey("virtual_items"), primary_key
>> = True) )
>>
>> table_article_proposals = Table("article_proposals", meta,
>> Column("id", Integer, ForeignKey("virtual_proposals"),
>> primary_key = True),
>> Column("body", UnicodeText),
>> )
>>
>> So as you can see the table "articles" is quite redundant because
>> it has only the primary key column but I didn't find any other way
>> to select articles directly from the table "virtual_items"
>> according to the column "kind" without joining to another
>> specialized table. Is there any way around this to omit the
>> "articles" table?
>>
>> Thanks for advices.
>>
>> David
>>
>>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---