2011-12-11 9 views
1

私はormとしてpython-stormを使用しています。多対多の参照セットは私を与えている。これらは、関連するオブジェクトです:(python-storm orm many-to-many

頭痛:

class Author(object): 
    __storm_table__ = "author" 
    id = Int(primary=True) 
    name = Unicode() 
    institution_id = Int() 
    institution = Reference(institution_id, Institution.id) 

    def __init__(self, name): 
     self.name = name 


class Paper(object): 
    __storm_table__ = "paper" 
    id = Int(primary=True) 
    name = Unicode() 
    conference_id = Int() 
    conference = Reference(conference_id, Conference.id) 

    def __init__(self, name): 
     self.name = name 

class AuthorPapers(object): 
    __storm_table__ = "authorpapers" 
    __storm_primary__ = "author_id", "paper_id" 
    author_id = Int() 
    paper_id = Int() 

している場合は、この

store.execute("CREATE TABLE if not exists author (id INTEGER PRIMARY KEY, name VARCHAR, institution_id INTEGER, FOREIGN KEY (institution_id) REFERENCES institution(id))") 

store.execute("CREATE TABLE if not exists paper (id INTEGER PRIMARY KEY, name VARCHAR, conference_id INTEGER, FOREIGN KEY (conference_id) REFERENCES conference(id))") 

store.execute("CREATE TABLE if not exists authorpapers (author_id INTEGER, paper_id INTEGER, PRIMARY KEY (author_id, paper_id))") 

のようなそれぞれのsqliteのテーブルルックを今言います2人の著者が論文でコラボレートした。

a = Author(u"Steve Rogers") 
b = Author(u"Captain America") 

と論文

p6 = Paper(u"Bunga Bunga") 

だから今、私は

Author.papers = ReferenceSet(Author.id, AuthorPapers.author_id, Paper.id, AuthorPapers.paper_id) 

を使って紙に両方の著者を関連付けると、この

a.papers.add(p6) 
b.papers.add(p6) 

をやっこれは、嵐のチュートリアルで働くことになっていると言いところであります。 ..しかし私は得る

File "/usr/lib64/python2.7/site-packages/storm/references.py", line 376, in add 
    self._relation2.link(remote, link, True) 
    File "/usr/lib64/python2.7/site-packages/storm/references.py", line 624, in link 
    pairs = zip(self._get_local_columns(local.__class__), 
    File "/usr/lib64/python2.7/site-packages/storm/references.py", line 870, in _get_local_columns 
    for prop in self.local_key) 
    File "/usr/lib64/python2.7/site-packages/storm/references.py", line 870, in <genexpr> 
    for prop in self.local_key) 
    File "/usr/lib64/python2.7/site-packages/storm/properties.py", line 53, in __get__ 
    return self._get_column(cls) 
    File "/usr/lib64/python2.7/site-packages/storm/properties.py", line 97, in _get_column 
    attr = self._detect_attr_name(cls) 
    File "/usr/lib64/python2.7/site-packages/storm/properties.py", line 82, in _detect_attr_name 
    raise RuntimeError("Property used in an unknown class") 
RuntimeError: Property used in an unknown class 

そして、私は本当にできない今、この感覚。

答えて

4

私は実際にstormに精通していませんが、documentationの例を見ると、ReferenceSetの引数が渡される順序に関連する問題のように見えます。

Author.papers = ReferenceSet(Author.id, AuthorPapers.author_id, Paper.id, AuthorPapers.paper_id) 

と例外が発生しなかった。これに代えて

Author.papers = ReferenceSet(Author.id, AuthorPapers.author_id, AuthorPapers.paper_id, Paper.id) 

:私はこれを使用しようとしました。

+0

恐ろしい!あなたほど。最近私はコードを凝視しているようだ;) – eeknay

関連する問題