在 DBIx::Class 中注入关系

发布于 2024-08-30 05:27:38 字数 419 浏览 2 评论 0原文

我有一些 DBIx::Class::Core 对象,用于对各种数据库表进行建模。

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

我还想让该类注入 has_many 关系,

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

但我似乎无法正确注册关系(不断收到“没有这样的关系”错误 - 但是,在调用关系方法时来源提供了关系)。

有什么线索表明出了什么问题吗?

I have a handful of DBIx::Class::Core objects that model various database tables.

For some of those models (those that have a 'queue' column), I have another class inject subs (basically, to 'move' the model object along it's queue states).

I'd like to also have that class inject has_many relationships ala

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

but I can't seem to get the relationships to register properly (keep getting "No Such Relationship" errors - however, when calling the relationship method on the sources provides back the relationship).

Any clues as to what's wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2024-09-06 05:27:38

经过一番研究后,发现以下方法有效:

$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 关系添加的所有适当的其他方法。

After some digging around, the following works:

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

The key being the unregister/register methods in order to generate all the appropriate other methods that get added by having a new has_many relationship.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文