2010-04-23 62 views
3

我有幾個DBIx :: Class :: Core對象爲各種數據庫表建模。在DBIx :: Class中注入關係

對於其中一些模型(那些有'隊列'列),我有另一個類注入subs(基本上,'移動'模型對象沿它的隊列狀態)。

我想也有一流的注入has_many關係ALA

class($name)->has_many('queue_history','MySchema::Result::QueueHistory', 
{ 'foreign.record_id'=>'self.id' }, 
{ where => { type => $name }}); 

,但我似乎無法得到的關係,正確註冊(不斷收到「無此類關係」的錯誤 - 但是,當調用源關係方法提供關係)。

任何線索有什麼不對?

+0

找到了解決方案,仍然很喜歡看替代品! – Carl 2010-04-23 23:48:17

回答

2

一些周圍挖掘,以下工作後:

$class = $schema->class($name)->has_many('queue_history','MySchema::Result::QueueHistory', 
{ 'foreign.record_id'=>'self.id' }, 
{ where => { type => $name }}); 

$schema->unregister_source($name); 
$schema->register_class($name,$class); 

的關鍵是爲了產生所有獲得由具有新has_many關係中加入適當的其他方法註銷/註冊方法。

相關問題