[storm] How to define two Storm tables that reference each other
Alec Henriksen
alecwh at gmail.com
Mon Feb 1 14:46:06 GMT 2010
Hello list,
I am defining my storm tables like this (in a file called objects.py):
class Article(object):
"""
This is a Storm table: articles
"""
__storm_table__ = "articles"
id_ = Int(primary=True)
url_id = Unicode()
title = Unicode()
tags = Unicode()
author = Unicode()
timestamp = Unicode()
content = Unicode()
comments = ReferenceSet(id_, Comment.article_id)
comment_count = len(comments)
ip = Unicode()
active = Int()
class Comment(object):
"""
This is a Storm table: articles
"""
__storm_table__ = "comments"
id_ = Int(primary=True)
author = Unicode()
article_id = Int()
article = Reference(article_id, Article.id_)
thread_id = Int()
timestamp = Unicode()
email = Unicode()
website = Unicode()
text = Unicode()
The problem is, obviously enough, I can't reference Comment.article_id
before I've defined Comment. I also can't switch the two classes around,
because both Comment and Article reference each other. Python gives me
this:
File "/var/www/alecwh/objects.py", line 34, in Article, referer:
http://localhost/
comments = ReferenceSet(id_, Comment.article_id), referer:
http://localhost/
NameError: name 'Comment' is not defined, referer: http://localhost/
So, does anybody have any recommendations for resolving this? Perhaps
I'm not thinking about this correctly. Thanks a lot in advance.
--
Alec Henriksen <alecwh at gmail.com> @ http://alecwh.com/
More information about the storm
mailing list