使用 Rose::DB::Object,如果找不到,如何在关系中自动创建对象?
我有 2 个 1-to-[0/1] 的表。有没有办法使用 Rose::DB 自动创建关系对象/行: :Object:
例如:
# detailed_summary is the 1-to-1 relationship
# if detailed_summary exist, get it
# if not, create a new one with links?
$obj->detailed_summary
也许是一个触发器?
I have 2 tables that are 1-to-[0/1]. Is there a way to auto create the relationship object/row using Rose::DB::Object:
For example:
# detailed_summary is the 1-to-1 relationship
# if detailed_summary exist, get it
# if not, create a new one with links?
$obj->detailed_summary
Maybe a trigger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
列触发器< /a> 不是你想要的。实现目标的一种方法是用前导下划线命名您的关系,然后编写自己的无下划线方法来执行“如果尚不存在则创建一个”的操作:
您也可以通过将创建后生成的Detailed_summary()方法,可以手动(使用类型团和子例程引用),也可以使用可以包装现有子例程的CPAN模块。
(上面的代码非常常规,如果您最终经常这样做,您应该能够自动创建它。)
A column trigger is not what you want. One way to accomplish your goal would be to name your relationships with leading underscores and then write your own underscore-less methods to do the "make one if it doesn't yet exist" thing:
You could also do the same thing by wrapping the generated detailed_summary() method after it's created, either manually (using typeglobs and subroutine references), or with a CPAN module that can wrap existing subroutines.
(The code above is quite regular and you should be able to automate its creation if you end up doing this a lot.)