[storm] How to define two Storm tables that reference each other
Fernando Correa Neto
fcdoth at gmail.com
Mon Feb 1 15:09:30 GMT 2010
Hello,
I think that quoting the table fields would solve the problem.
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()
Cheers,
Fernando
On Mon, Feb 1, 2010 at 12:46 PM, Alec Henriksen <alecwh at gmail.com> wrote:
> 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/
>
>
> --
> storm mailing list
> storm at lists.canonical.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
>
More information about the storm
mailing list