DBIx::Class - 此关系缓存在哪里?
我有一个 Order 实体和一个 Address 实体,在我的 Schema::Result::Order
模块中,我有一个简单的所属关系:
__PACKAGE__->belongs_to( "address", 'Schema::Result::Address',
{ addressid => 'addressid' });
我使用 DBIC_TRACE=1
运行此代码>:
my $order = $schema->resulset('Order')->find($id);
my $add1 = $order->address;
my $add2 = $order->address;
我只看到一个 SELECT ... FROM ADDRESS ... 查询,因此显然第二个 $order->address
方法没有访问数据库。
所以这可能是一个简单的问题,但是地址对象缓存在哪里? (在 $order
对象中?)
其次,此缓存是否可配置(即我可以将 DBIC 配置为不缓存这些关系)吗?
I have an Order entity and an Address entity, and in my Schema::Result::Order
module I have a simple belongs to relationship:
__PACKAGE__->belongs_to( "address", 'Schema::Result::Address',
{ addressid => 'addressid' });
I run this code with DBIC_TRACE=1
:
my $order = $schema->resulset('Order')->find($id);
my $add1 = $order->address;
my $add2 = $order->address;
and I only see one SELECT ... FROM ADDRESS ...
query, so apparently the second $order->address
method is not hitting the database.
So this might be a simple question, but where is the address object getting cached? (in the $order
object?)
Secondly, is this caching configurable (i.e. can I configure DBIC to not cache these relationships)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的订单与地址关系的方式您将只有一个订单地址:
如果您的订单将有许多您想要的地址:
那么您可以通过多种方式检索地址:
我不确定如何缓存在这种情况下有效
但是如果您像这样访问地址记录:
您可以使用查询属性控制它:
https://metacpan.org/module/DBIx::Class::ResultSet#cache
I think the way you have your order to address relationship you will only have one address to the order:
If your order will have many addresses you will want:
Then you can retrieve the addresses a number of ways:
I am not sure how the caching works in this situation
But if you access your address record like this:
you can control it with your query attributes:
https://metacpan.org/module/DBIx::Class::ResultSet#cache
找到答案:它缓存在
$order->{_relationship_data}->{address}
中。尚未确定是否可以禁用该缓存。
Found the answer: it's cached in
$order->{_relationship_data}->{address}
.Haven't determined if that caching can be disabled.