2014-08-27 59 views
0

我想實現一個有很多通過關係闡述here。但是,我的相關模型與通過自連接的引用模型相同。我嘗試這樣做:有很多通過自我加入batmanjs

class Article extends Batman.Model 
    @hasMany 'citations' 
    @hasMany 'usages', name: 'Citation', foreignKey: 'referenced_article_id' 

    @accessor 'referenced_articles', -> 
    @get('citations').mappedTo('referenced_article') 

class Citation extends Batman.Model 
    @belongsTo 'article' 
    @belongsTo 'referenced_article', name: 'Article' 

不幸的是,呼籲my_article.get('referenced_articles')給出了一個錯誤。有任何想法嗎?

回答

0

啊,拍攝。我沒有在0.16中加mappedToSetProxy。它的固定與此PR:https://github.com/batmanjs/batman/pull/1052

您既可從batmanjs.org/download.html或猴子補丁它得到主人:

Batman.AssociationSet::mappedTo = Batman.Set::mappedTo 

(這是我在做什麼,直到我更新到主)

對不起!

+0

您可以從網站(http://batmanjs.org/download.html)下載蝙蝠俠/主人,但它有一些其他突破性更改(請參閱https://github.com/batmanjs/batman/issues/1106) 。 在捏,你可以在你的應用定義之前添加那行^^。我在修復它之前先修好它。 – rmosolgo 2014-08-28 14:27:23

0

由於您的協會被命名爲usages(不citations),你可以嘗試:

@accessor 'referenced_articles', -> 
    @get('usages').mappedTo('referenced_article') 
+0

不,仍然不起作用。它看起來像'mappedTo'沒有被定義。 AssociationSet(用法)我稱之爲具有相關項目(參考文章)。我也有最新版本的蝙蝠俠(V0.16.0),所以不應該是問題更嚴重。 – 2014-08-27 17:01:15