代码之家  ›  专栏  ›  技术社区  ›  Carl

在DBIx::类中注入关系

  •  3
  • Carl  · 技术社区  · 14 年前

    对于其中一些模型(具有“queue”列的模型),我有另一个类injectsubs(基本上是沿着模型对象的队列状态“移动”模型对象)。

    我还想上那个班 has_many 关系ala

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

    1 回复  |  直到 14 年前
        1
  •  2
  •   Carl    14 年前

    经过一番挖掘,以下工作:

    $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);
    

    密钥是unregister/register方法,以便生成通过拥有新的 has_many 关系。