On Thursday, June 10, 2010 04:36:13 David Zaslavsky wrote:
> Hi everyone,
>
> I've been using Elixir in my website for a while, but I think what I'm
> trying to do now is beyond my skill level, so I'm wondering if someone can
> help. Basically I'm writing a blog engine. (Like everyone else, I know)
> Well, not just a blog engine - it has bloggish features, like comments and
> tags, but there are also a variety of different things (i.e. more than
> just blog posts) that can have tags or comments. So my first thought was
> to make a Taggable class to serve as a superclass of anything that could
> be tagged, and a Commentable class to serve as a superclass of anything
> that could be commented on.
>
> class Tag(Entity):
> name = Field(Unicode(128), primary_key=True)
> tagged = ManyToMany('Taggable')
> class Taggable(Entity):
> tags = ManyToMany('Tag')
> class Comment(Entity):
> text = Field(UnicodeText)
> parent = ManyToOne('Commentable')
> class Commentable(Entity):
> comments = OneToMany('Comment')
>
> The experts on this list can probably see where this is going: when I try
> to do a concrete implementation like so:
>
> class Post(Taggable,Commentable):
> text = Field(UnicodeText)
>
> I get an error:
>
> Exception: Post entity inherits from several entities, and this is not
> supported.
>
> So I wanted to ask, is there some recommended way to do what I'm trying to
> do? (Is it actually possible?) I need the association to work both ways,
> e.g. I need to be able to easily access both the parent of a Comment, and
> all comments attached to the parent. Any recommendations, suggestions, or
> solutions would be much appreciated.
I think the solution is to have commentable and taggable not derive from
entity. Thus subclassing from them simply leads to add those relations.
However, this of course introduces one n:m table for each taggable or
commentable, or one key column for each commentable on the comments table.
The only way out of this would be to have on base class, "Thing", that is
taggable & commentable & serves as base for all those entities.
Not nice either - you gotta die one death here :)
Diez
--
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en.